You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.0 KiB

4 years ago
using CK.SCP.Models;
using CK.SCP.Models.ScpEntity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Migrations;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CK.SCP.UniApi
{
public partial class test1 : Form
{
public test1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
UpdateVender(db,db, "",(ret)=>{
richTextBox1.Text = ret;
});
}
}
private static void UpdateVender(ScpEntities idb, ScpEntities wdb, string seq ,Action<string> p_action)
{
var ls = new List<string>();
var qadDataList = idb.xxqad_vd_mstr.ToList();
var wmsDataList = new List<TA_VENDER>();
foreach (var qadData in qadDataList)
{
try
{
var wmsData = wdb.TA_VENDER.SingleOrDefault(p => p.VendId == qadData.xxqad_vd_addr.ToUpper()) ??
new TA_VENDER { VendId = qadData.xxqad_vd_addr.ToUpper(), VendAbbCode = "0", State = 1 };
wmsData.VendName = qadData.xxqad_vd_name;
wmsData.VendType = qadData.xxqad_vd_type.ToUpper().ToString();
wmsData.Country = qadData.xxqad_vd_country;
wmsData.City = qadData.xxqad_vd_city;
wmsData.Currency = qadData.xxqad_vd_curr.ToUpper();
// wmsData.Promo = qadData.xxqad_vd_promo; //国内国外
wmsData.Address = qadData.xxqad_vd_line1 + qadData.xxqad_vd_line2 + qadData.xxqad_vd_line3;
wmsData.ZipCode = qadData.xxqad_vd_pst_id;
wmsData.Contacter = qadData.xxqad_vd_attn;
wmsData.Phone = qadData.xxqad_vd_phone;
wmsData.Fax = qadData.xxqad_vd_fax;
// wmsData.Email = ""; //QAD无此项
wmsData.Tax = qadData.xxqad_vd_tax;//税率
if (wmsDataList.Count(p => p.VendId == wmsData.VendId) == 0)
{
wmsDataList.Add(wmsData);
}
//qadData.xxqad_vd_scmread = ((int)UniApiState.成功).ToString();
}
catch (Exception ex)
{
// qadData.xxqad_vd_scmread = ((int)UniApiState.失败).ToString();
qadData.xxqad_vd_rmks += " SCM:" + ex.Message;
}
qadData.xxqad_vd_updateur = ScpCache.Config.SCP用户名;
qadData.xxqad_vd_updatedt = DateTime.Now;
}
try
{
wdb.TA_VENDER.AddOrUpdate(wmsDataList.Where(p => !string.IsNullOrEmpty(p.VendName)).ToArray());
wdb.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
{
var sb = new StringBuilder();
foreach (var error in dbEx.EntityValidationErrors.ToList())
{
error.ValidationErrors.ToList().ForEach(i =>
{
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
});
}
ls.Add(sb.ToString());
}
catch (Exception e)
{
ls.Add(e.Message);
}
p_action( string.Join("\r\n", ls.ToArray()));
Console.WriteLine($"更新 供应商 数据:{qadDataList.Count}");
}
}
}