public async Task SyncSOCancels() { Console.WriteLine("Syncing SOCancels..."); try { using (var erpdb = new ERPAPPTRAINEntities()) { erpdb.sptyx_SOCancel(); Console.WriteLine("Synced SOCancels..."); } } catch (Exception e) { Console.WriteLine(e.GetBaseException().Message); } }
public async Task SyncARInvoices() { log.Information("Syncing ARInvoices..."); try { using (var erpdb = new ERPAPPTRAINEntities()) { var arInvoices = erpdb.sptyx_DMSARInvoice().ToList(); var totalRow = arInvoices.Count(); using (var db = new EpicorIntergrationEntities()) { int runningRow = 0; var addedARInvoiceHeaders = new List <ARINVOICE_HEADER>(); var addedARInvoiceDetails = new List <ARINVOICE_DETAIL>(); foreach (var arInvoice in arInvoices) { runningRow++; if (!db.ARINVOICE_HEADER.Any(p => p.CompanyCode == arInvoice.Company && p.DocNum == arInvoice.Docnum.ToString()) && !addedARInvoiceHeaders.Any(p => p.CompanyCode == arInvoice.Company && p.DocNum == arInvoice.Docnum.ToString())) { try { var arInvoiceHeader = new ARINVOICE_HEADER(); MapHeaderToEntity(arInvoiceHeader, arInvoice); arInvoiceHeader.ARINVOICE_DMSFLAG = "N"; addedARInvoiceHeaders.Add(arInvoiceHeader); //await db.SaveChangesAsync(); Console.WriteLine($"[{runningRow}/{totalRow}]Added arInvoiceHeader: #{arInvoice.Docnum}"); } catch (Exception e) { log.Error($"Failed adding arInvoiceHeader: #{arInvoice.Company}/{arInvoice.Docnum} - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Failed adding arInvoiceHeader: #{arInvoice.Company}/{arInvoice.Docnum}"); Console.WriteLine(e.GetBaseException().Message); continue; } } if (!db.ARINVOICE_DETAIL.Any(p => p.CompanyCode == arInvoice.Company && p.DocNum == arInvoice.Docnum.ToString() && p.LineNum == arInvoice.Linenum.ToString()) && !addedARInvoiceDetails.Any(p => p.CompanyCode == arInvoice.Company && p.DocNum == arInvoice.Docnum.ToString() && p.LineNum == arInvoice.Linenum.ToString())) { try { var arInvoiceDetail = new ARINVOICE_DETAIL(); MapDetailToEntity(arInvoiceDetail, arInvoice); addedARInvoiceDetails.Add(arInvoiceDetail); //await db.SaveChangesAsync(); Console.WriteLine($"[{runningRow}/{totalRow}]Added arInvoiceDetail: #{arInvoice.Docnum}"); } catch (Exception e) { log.Error($"Failed adding arInvoiceDetail: #{arInvoice.Company}/{arInvoice.Docnum} - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Failed adding arInvoiceDetail: #{arInvoice.Company}/{arInvoice.Docnum}"); Console.WriteLine(e.GetBaseException().Message); continue; } } } if (addedARInvoiceHeaders.Any()) { db.ARINVOICE_HEADER.AddRange(addedARInvoiceHeaders); } if (addedARInvoiceDetails.Any()) { db.ARINVOICE_DETAIL.AddRange(addedARInvoiceDetails); } await db.SaveChangesAsync(); } } //bool more = true; //int page = 0; //DateTime expired = DateTime.Now.AddMinutes(10); //while (more && expired >= DateTime.Now) //{ // page++; // Console.WriteLine($"Working on AR Invoice Header page: #{page}"); // var rs = await arInvoiceClient.GetRowsAsync(new Epicor.ARInvoiceSvc.GetRowsRequest() // { // pageSize = 5, // absolutePage = page // }); // var result = rs.GetRowsResult; // more = rs.morePages; // using (var db = new EpicorIntergrationEntities()) // { // //Header // var invcHeads = result.InvcHead.ToArray(); // foreach (var invcHead in invcHeads) // { // var arInvoiceHeader = db.ARINVOICE_HEADER.FirstOrDefault(p => p.InvoiceNum == invcHead.InvoiceNum); // if (arInvoiceHeader == null) // { // arInvoiceHeader = new ARINVOICE_HEADER(); // arInvoiceHeader.DMSFlag = "N"; // MapHeaderToEntity(arInvoiceHeader, invcHead); // db.ARINVOICE_HEADER.Add(arInvoiceHeader); // Console.WriteLine($"Added AR Invoice Header: #{invcHead.InvoiceNum}"); // } // else // { // MapHeaderToEntity(arInvoiceHeader, invcHead); // arInvoiceHeader.DMSFlag = "U"; // db.ARINVOICE_HEADER.Attach(arInvoiceHeader); // db.Entry(arInvoiceHeader).State = System.Data.Entity.EntityState.Modified; // Console.WriteLine($"Updated AR Invoice Header: #{invcHead.InvoiceNum}"); // } // } // //Detail // var invcDtls = result.InvcDtl.ToArray(); // foreach (var invcDtl in invcDtls) // { // var arInvoiceDetail = db.ARINVOICE_DETAIL.FirstOrDefault(p => p.InvoiceNum == invcDtl.InvoiceNum && p.InvoiceLine == invcDtl.InvoiceLine); // if (arInvoiceDetail == null) // { // arInvoiceDetail = new ARINVOICE_DETAIL(); // arInvoiceDetail.DMSFlag = "N"; // MapDetailToEntity(arInvoiceDetail, invcDtl); // db.ARINVOICE_DETAIL.Add(arInvoiceDetail); // Console.WriteLine($"Added AR Invoice Detail: #{invcDtl.InvoiceNum}"); // } // else // { // MapDetailToEntity(arInvoiceDetail, invcDtl); // arInvoiceDetail.DMSFlag = "U"; // db.ARINVOICE_DETAIL.Attach(arInvoiceDetail); // db.Entry(arInvoiceDetail).State = System.Data.Entity.EntityState.Modified; // Console.WriteLine($"Updated AR Invoice Detail: #{invcDtl.InvoiceNum}"); // } // } // //Save all // await db.SaveChangesAsync(); // } //} } catch (Exception e) { Console.WriteLine(e.GetBaseException().Message); } }
public async Task SyncParts() { log.Information("Syncing Parts..."); Console.WriteLine("Syncing Parts..."); try { using (var erpdb = new ERPAPPTRAINEntities()) { using (var db = new EpicorIntergrationEntities()) { var sysRevID = db.PRODUCTs.Max(p => p.SysRevID); var ud_SysRevID = db.PRODUCTs.Max(p => p.UD_SysRevID); var parts = erpdb.sptyx_DMSProduct(sysRevID, ud_SysRevID).ToList(); foreach (var part in parts) { var product = db.PRODUCTs.FirstOrDefault(p => p.ItemCode == part.ItemCode && p.Company == part.Company); if (product == null) { try { product = Mapper.Map <PRODUCT>(part); product.DMSFlag = "N"; db.PRODUCTs.Add(product); //await db.SaveChangesAsync(); Console.WriteLine($"Added product: #{part.ItemCode}"); } catch (Exception e) { log.Error($"Failed adding product: #{part.ItemCode} - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Failed adding product: #{part.ItemCode}"); Console.WriteLine(e.GetBaseException().Message); continue; } } else { try { Mapper.Map(part, product); product.DMSFlag = "U"; db.PRODUCTs.Attach(product); db.Entry(product).State = System.Data.Entity.EntityState.Modified; //await db.SaveChangesAsync(); Console.WriteLine($"Updated product: #{part.ItemCode}"); } catch (Exception e) { log.Error($"Failed updating product: #{part.ItemCode} - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Failed updating product: #{part.ItemCode}"); Console.WriteLine(e.GetBaseException().Message); continue; } } } await db.SaveChangesAsync(); } } } catch (Exception e) { log.Error($"System error: {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine(e.GetBaseException().Message); } }
public async Task SyncPrices() { log.Information("Syncing Prices..."); Console.WriteLine("Syncing Prices..."); try { //var rs = await priceClient.GetRowsAsync(new Epicor.PriceLstPartsSvc.GetRowsRequest()); //var result = rs.GetRowsResult; //var priceLstParts = result.PriceLstParts.ToArray(); using (var erpdb = new ERPAPPTRAINEntities()) { var priceLstParts = erpdb.sptyx_DMSPriceList().ToList(); var totalRow = priceLstParts.Count(); using (var db = new EpicorIntergrationEntities()) { int runningRow = 0; foreach (var priceLstPart in priceLstParts) { runningRow++; var price = db.PRICE_LIST.FirstOrDefault(p => p.Company == priceLstPart.Company && p.PriceListNum == priceLstPart.PriceListNum && p.Partnum == priceLstPart.PartNum); if (price == null) { try { price = Mapper.Map <PRICE_LIST>(priceLstPart); price.DMSFlag = "N"; db.PRICE_LIST.Add(price); //await db.SaveChangesAsync(); Console.WriteLine($"[{runningRow}/{totalRow}]Added price: #{priceLstPart.Company}/{priceLstPart.PriceListNum}/{priceLstPart.PartNum}"); } catch (Exception e) { log.Error($"Failed adding price: #{priceLstPart.Company}/{priceLstPart.PriceListNum}/{priceLstPart.PartNum} - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Failed adding price: #{priceLstPart.Company}/{priceLstPart.PriceListNum}/{priceLstPart.PartNum}"); Console.WriteLine(e.GetBaseException().Message); continue; } } else { try { Mapper.Map(priceLstPart, price); price.DMSFlag = "U"; db.PRICE_LIST.Attach(price); db.Entry(price).State = System.Data.Entity.EntityState.Modified; //await db.SaveChangesAsync(); Console.WriteLine($"[{runningRow}/{totalRow}]Updated price: #{priceLstPart.Company}/{priceLstPart.PriceListNum}/{priceLstPart.PartNum}"); } catch (Exception e) { log.Error($"Failed updating price: #{priceLstPart.Company}/{priceLstPart.PriceListNum}/{priceLstPart.PartNum} - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Failed updating price: #{priceLstPart.PriceListNum}"); Console.WriteLine(e.GetBaseException().Message); continue; } } } await db.SaveChangesAsync(); } } } catch (Exception e) { log.Error($"System error: {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine(e.GetBaseException().Message); } }
public async Task SyncCustInfos() { log.Information("Syncing CustInfos..."); try { using (var erpdb = new ERPAPPTRAINEntities()) { var custInfos = erpdb.sptyx_DMSCustInfo().ToList(); var totalRow = custInfos.Count(); using (var db = new EpicorIntergrationEntities()) { int runningRow = 0; foreach (var custInfo in custInfos) { runningRow++; var cod = db.CUSTOMER_INFO.FirstOrDefault(p => p.Custnum == custInfo.Custnum && p.Company == custInfo.Company); if (cod == null) { try { cod = Mapper.Map <CUSTOMER_INFO>(custInfo); cod.DMSFlag = "N"; db.CUSTOMER_INFO.Add(cod); //await db.SaveChangesAsync(); Console.WriteLine($"[{runningRow}/{totalRow}]Added Cust Info: #{custInfo.Company}/{custInfo.Custnum}"); } catch (Exception e) { log.Error($"Failed adding Cust Info: #{custInfo.Company}/{custInfo.Custnum}", e.GetBaseException()); Console.WriteLine($"Failed adding Cust Info: #{custInfo.Custnum}"); Console.WriteLine(e.GetBaseException().Message); continue; } } else { try { Mapper.Map(custInfo, cod); cod.DMSFlag = "U"; db.CUSTOMER_INFO.Attach(cod); db.Entry(cod).State = System.Data.Entity.EntityState.Modified; //await db.SaveChangesAsync(); Console.WriteLine($"[{runningRow}/{totalRow}]Updated Cust Info: #{custInfo.Company}/{custInfo.Custnum}"); } catch (Exception e) { log.Error($"Failed updating Cust Info: #{custInfo.Company}/{custInfo.Custnum}", e.GetBaseException()); Console.WriteLine($"Failed updating Cust Info: #{custInfo.Company}/{custInfo.Custnum}"); Console.WriteLine(e.GetBaseException().Message); continue; } } } await db.SaveChangesAsync(); } } } catch (Exception e) { log.Error($"System error: {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine(e.GetBaseException().Message); } }