using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using cuidian.Common;
using cuidian.OpenApi.Api;
using cuidian.OpenApi.Model;
using cuidian.OpenApi.Utils;
using OperationLog;
using cuidian.Sql;
namespace TempDbToUfida.OpenApi
{
///
/// 从中间库将供应商资料下载到U8数据库
///
public class DownLoadVendor : BaseDataDownLoad
{
protected override void _Init()
{
_loadSql = "select * from vendor where processflag=0";
base._Init();
}
private Dictionary _u8Column =new Dictionary();
protected override BusinessObject _ImportData(DataRow row)
{
VendorApi api = new VendorApi();
Vendor v = new Vendor();
v.code = row["cvencode"].ToString();//供应商编码
v.sort_code = "01";
v.abbrname = row["cVenAbbName"].ToString();
v.name = row["cvenname"].ToString();
v.contact = row["cvenperson"].ToString();
if (string.IsNullOrWhiteSpace(row["phone"].ToString()))
{
v.phone = row["mobile"].ToString();
}
else
{
v.phone = row["cVenPhone"].ToString();
}
//v.phone = row["phone"].ToString();
//v.mobile = row["mobile"].ToString();
v.fax = row["fax"].ToString();
v.email = row["email"].ToString();
v.address = row["address"].ToString();
v.memo = row["cmemo"].ToString();
VendorRoot vr = new VendorRoot();
vr.vendor = v;
BusinessObject result = api.Add(JsonUtils.GetJsonString(vr));
//------------通过ado插入u8--------------------------
_u8Column["cVenDefine11"]= row["cVenDefine11"].ToString();
_u8Column["cVenDefine4"] = row["cVenDefine4"].ToString();
_u8Column["cVenDefine5"] = row["cVenDefine5"].ToString();
_u8Column["cVenDefine7"] = row["cVenDefine7"].ToString();
return result;
}
protected override void _LogError(int id, string msg)
{
OperationLog.Utils.WriteErrorLog("向U8导入供应商资料", "sysid = " + id.ToString() + " " + msg);
}
protected override void _LogSucess(int id, string newCode)
{
string sql = string.Format(@" update {0}..vendor set cVenPostCode='{1}' ,cVenDefine4='{2}',cVenDefine5='{3}',cVenDefine7='{4}' where cVencode='{5}' ", ConnectionUtils.Instance.GetConnection().Database, _u8Column["cVenDefine11"], _u8Column["cVenDefine4"], _u8Column["cVenDefine5"], _u8Column["cVenDefine7"], newCode);
sql += " update vendor set processflag = 1,processdate = getdate() where sysid = " + id.ToString();
OperationLog.Utils.UpdateTempRecord(sql);
}
}
}