package com.topsun.posclient.system.dao;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Text;
import com.topsun.posclient.common.LoggerUtil;
import com.topsun.posclient.common.dao.BaseDao;
import com.topsun.posclient.system.MessageResources;
import com.topsun.posclient.system.SyncProgress;
import com.topsun.posclient.system.SystemActivator;
import com.topsun.posclient.system.service.SyncDataListenerManager;
/**
* 数据同步处理
*
* @author Lilei
*
*
*/
public class LocalSyncDataDao extends BaseDao {
/**
* 同步用户数据
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadUserData(final SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
SyncDataListenerManager.getInstance().fireChange( "---------------> " + MessageResources.message_tips_startsyncuser);
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步用户数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步用户数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> " + MessageResources.message_tips_endsyncuser, count);
}
});
}
/**
* 同步店铺数据
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadShopData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange(
"---------------> "
+ MessageResources.message_tips_startsyncshop);
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步店铺数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步店铺数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> " + MessageResources.message_tips_endsyncshop, count);
}
});
}
/**
* 同步物料数据
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadMaterialData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange(
"---------------> 开始同步物料数据");
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步物料数据失败", e);
SyncDataListenerManager.getInstance()
.fireChange("同步物料数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange(
"---------------> 完成物料数据同步", count);
}
});
}
/**
* 同步促销方案数据
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadPromotionData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> 开始同步促销方案数据");
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步载促销方案数据失败", e);
SyncDataListenerManager.getInstance().fireChange( "同步载促销方案数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> 完成促销方案数据同步", count);
}
});
}
/**
* 同步单品数据
* @param progress
* @param count
* @throws Exception
*/
public void downloadItemData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> "+ MessageResources.message_tips_startsyncitem);
while (true) {
try {
} catch (Exception e) {
e.printStackTrace();
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步商品主数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步商品主数据失败");
return;
}
}
}
});
}
/**
* 同步结算方式数据
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadCashierModeData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
SyncDataListenerManager
.getInstance()
.fireChange(
"---------------> "
+ MessageResources.message_tips_startsynccashiermode);
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步结算方式数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步结算方式数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange( "---------------> " + MessageResources.message_tips_endsynccashiermode,count);
}
});
}
/**
* 同步实时金价数据
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadGoldPriceData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> 开始同步实时金价数据");
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步实时金价数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步实时金价数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> 完成实时金价数据同步", count);
}
});
}
/**
* 同步打印模板
*
* @param progress
* @param count
* @throws Exception
*/
public void downloadPrintTemplateData(SyncProgress progress, final int count) throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> 开始同步打印模板数据");
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步打印模板数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步打印模板数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> 完成打印模板数据同步", count);
}
});
}
/**
* 会员数据同步
* @param progress
* @param count
* @throws Exception
*/
public void downloadMemberData(SyncProgress progress,final int count) throws Exception{
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> 开始同步会员数据");
try {
} catch (Exception e) {
e.printStackTrace();
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "同步会员数据失败", e);
SyncDataListenerManager.getInstance().fireChange("同步会员数据失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> 完成会员数据同步",count);
}
});
}
/**
* 上传零售数据
*
* @param progress
* @param count
* @throws Exception
*/
public void uploadPartSalesData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> " + MessageResources.message_tips_startsyncsales);
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "零售数据上传失败", e);
SyncDataListenerManager.getInstance().fireChange("零售数据上传失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> " + MessageResources.message_tips_endsyncsales, count);
}
});
}
/**
* 上传退换货数据
*
* @param progress
* @param count
* @throws Exception
*/
public void uploadReturnedData(SyncProgress progress, final int count)
throws Exception {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SyncDataListenerManager.getInstance().fireChange("---------------> 开始上传退换货数据");
try {
} catch (Exception e) {
LoggerUtil.logError(SystemActivator.PLUGIN_ID, "退货数据上传失败", e);
SyncDataListenerManager.getInstance() .fireChange("退货数据上传失败");
return;
}
SyncDataListenerManager.getInstance().fireChange("---------------> 完成退换货数据上传", count);
}
});
}
/**
* 进度显示显示线程
*
* @param infoText
* @param text
*/
public void createDisplayThread(final Text infoText, final String text) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
{
String str = infoText.getText() + "\r\n";
infoText.setText(str + text);
}
}
});
}
public void setProgress(final ProgressBar bar, final int worked) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
{
bar.setSelection(worked);
}
}
});
}
}