예제 #1
0
        public async Task SyncPartTrans(string company)
        {
            log.Information("Syncing PartTrans...");
            Console.WriteLine($"Syncing {company} PartTrans...");
            try
            {
                using (var db = new EpicorIntergrationEntities())
                {
                    string siteID, siteName, workstationID, workstationDescription, employeeID, countryGroupCode, countryCode, tenantID, companyName, systemCode;
                    sessionModClient.SetCompany(company, out siteID, out siteName, out workstationID, out workstationDescription, out employeeID, out countryGroupCode, out countryCode, out tenantID);

                    bool     more    = true;
                    int      page    = 0;
                    DateTime expired = DateTime.Now.AddMinutes(10);
                    while (more && expired >= DateTime.Now)
                    {
                        page++;
                        Console.WriteLine($"Working on PartTran page: #{page}");
                        var rs = await partTranClient.GetRowsAsync(new Epicor.PartTranSvc.GetRowsRequest()
                        {
                            pageSize            = 5,
                            absolutePage        = page,
                            whereClausePartTran = "(TranType = 'STK-UKN' OR TranType = 'PUR-STK') AND TranDate >= '2017-9-1'"
                        });

                        var result    = rs.GetRowsResult;
                        var partTrans = result.PartTran.ToArray();
                        more = rs.morePages;

                        foreach (var partTran in partTrans)
                        {
                            var invtTrans = db.INVT_TRANS.FirstOrDefault(p => p.TranNum == partTran.TranNum);
                            if (invtTrans == null)
                            {
                                invtTrans         = new INVT_TRANS();
                                invtTrans.DMSFlag = "N";
                                MapToEntity(invtTrans, partTran);
                                db.INVT_TRANS.Add(invtTrans);
                                Console.WriteLine($"Added invt trans: #{partTran.TranNum}");
                            }
                            //else
                            //{
                            //    MapToEntity(invtTrans, partTran);
                            //    invtTrans.DMSFlag = "U";
                            //    db.INVT_TRANS.Attach(invtTrans);
                            //    db.Entry(invtTrans).State = System.Data.Entity.EntityState.Modified;
                            //    Console.WriteLine($"Updated invt trans: #{partTran.TranNum}");
                            //}
                        }
                    }
                    await db.SaveChangesAsync();
                }

                sessionModClient.Logout();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetBaseException().Message);
            }
        }
예제 #2
0
        public async Task SyncCustomers()
        {
            Console.WriteLine("Syncing Customers...");
            try
            {
                using (var db = new EpicorIntergrationEntities())
                {
                    var addedCustomers = db.CUSTOMERs.Where(c => c.DMSFlag == "N");
                    //var updatedCustomers = db.CUSTOMERs.Where(c => c.DMSFlag == "U");
                    if (addedCustomers.Any() /* || updatedCustomers.Any()*/)
                    {
                        foreach (var customer in addedCustomers)
                        {
                            try
                            {
                                string siteID, siteName, workstationID, workstationDescription, employeeID, countryGroupCode, countryCode, tenantID, companyName, systemCode;

                                var currentCompany = sessionModClient.GetCurrentValues(out companyName, out siteID, out siteName, out employeeID, out workstationID, out workstationDescription, out systemCode, out countryGroupCode, out countryCode, out tenantID);

                                if (currentCompany != customer.CompanyCode)
                                {
                                    sessionModClient.SetCompany(customer.CompanyCode, out siteID, out siteName, out workstationID, out workstationDescription, out employeeID, out countryGroupCode, out countryCode, out tenantID);
                                }
                                CustomerTableset customerTableset = new CustomerTableset();
                                customerClient.GetNewCustomer(ref customerTableset);
                                var customerRow = customerTableset.Customer.Where(p => p.RowMod == "A").FirstOrDefault();
                                if (customerRow != null)
                                {
                                    MapToCustomerRow(customerRow, customer);
                                    customerClient.Update(ref customerTableset);
                                    var custNum   = customerTableset.Customer[0].CustNum;
                                    var shipToRow = customerTableset.ShipTo.FirstOrDefault();
                                    if (shipToRow != null)
                                    {
                                        MapToShipToRow(shipToRow, customer);
                                        shipToRow.RowMod = "U";
                                        customerClient.Update(ref customerTableset);
                                        Console.WriteLine($"Added customer ship to 1: #{customer.CustomerCode} successfully!");
                                        //customerRow.ShipToNum = "";
                                        //customerRow.RowMod = "U";
                                        //shipToRow.ShipToNum = "";
                                        //shipToRow.RowMod = "U";
                                        //customerClient.Update(ref customerTableset);
                                        //Console.WriteLine($"Updated default ship to: #{customer.CustomerCode} successfully!");

                                        var customerShipTo = db.CUSTOMER_SHIPTO.FirstOrDefault(cst => cst.CustomerCode == customer.CustomerCode);
                                        if (customerShipTo != null)
                                        {
                                            customerClient.GetNewShipTo(ref customerTableset, custNum);
                                            var shipToRow2 = customerTableset.ShipTo.FirstOrDefault(s => s.RowMod == "A");
                                            MapToShipToRow(shipToRow2, customerShipTo);
                                            //customerRow.ShipToNum = shipToRow2.ShipToNum;
                                            //customerRow.RowMod = "U";
                                            customerClient.Update(ref customerTableset);
                                            //customerShipTo.DMSFlag = "S";
                                            Console.WriteLine($"Added customer ship to 2: #{customer.CustomerCode} successfully!");
                                        }
                                    }
                                    //customer.DMSFlag = "S";
                                    Console.WriteLine($"Added customer: #{customer.CustomerCode} successfully!");
                                }
                            }
                            catch (Exception e)
                            {
                                //customer.DMSFlag = "F";
                                customer.SystemLog = $"Added customer: #{customer.CustomerCode} failed! - {e.Message}";
                                Console.WriteLine($"Added customer: #{customer.CustomerCode} failed! - {e.Message}");
                                Console.WriteLine(e.GetBaseException().Message);
                                continue;
                            }
                        }

                        //foreach(var customer in updatedCustomers)
                        //{
                        //    try
                        //    {
                        //        string siteID, siteName, workstationID, workstationDescription, employeeID, countryGroupCode, countryCode, tenantID, companyName, systemCode;

                        //        var currentCompany = sessionModClient.GetCurrentValues(out companyName, out siteID, out siteName, out employeeID, out workstationID, out workstationDescription, out systemCode, out countryGroupCode, out countryCode, out tenantID);

                        //        if (currentCompany != customer.CompanyCode)
                        //        {
                        //            sessionModClient.SetCompany(customer.CompanyCode, out siteID, out siteName, out workstationID, out workstationDescription, out employeeID, out countryGroupCode, out countryCode, out tenantID);
                        //        }
                        //        CustomerTableset customerTableset = customerClient.GetByCustID(customer.CustomerCode, true);
                        //        var customerRow = customerTableset.Customer.FirstOrDefault();
                        //        if (customerRow != null)
                        //        {
                        //            customerRow.RowMod = "U";
                        //            MapToCustomerRow(customerRow, customer);
                        //            customerClient.Update(ref customerTableset);
                        //            customer.DMSFlag = "S";
                        //            Console.WriteLine($"Updated customer: #{customer.CustomerCode} successfully!");
                        //        }
                        //    }
                        //    catch (Exception e)
                        //    {
                        //        //customer.DMSFlag = "F";
                        //        Console.WriteLine($"Updated customer: #{customer.CustomerCode} failed! - {e.Message}");
                        //        Console.WriteLine(e.GetBaseException().Message);
                        //        continue;
                        //    }
                        //}

                        await db.SaveChangesAsync();
                    }

                    sessionModClient.Logout();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetBaseException().Message);
            }
        }
예제 #3
0
        public async Task SyncSOs()
        {
            log.Information("Syncing SOs...");
            Console.WriteLine($"Syncing SOs...");
            try
            {
                using (var db = new EpicorIntergrationEntities())
                {
                    //Header
                    var addedSOHeaders = db.SO_HEADER.Where(c => c.DMSFlag == "N" /*c.DMSFlag == "N" || c.DMSFlag == "U"*/).OrderBy(h => h.CompanyCode);
                    if (addedSOHeaders.Any())
                    {
                        foreach (var soHeader in addedSOHeaders)
                        {
                            try
                            {
                                string siteID, siteName, workstationID, workstationDescription, employeeID, countryGroupCode, countryCode, tenantID, companyName, systemCode;

                                var currentCompany = sessionModClient.GetCurrentValues(out companyName, out siteID, out siteName, out employeeID, out workstationID, out workstationDescription, out systemCode, out countryGroupCode, out countryCode, out tenantID);

                                if (currentCompany != soHeader.CompanyCode)
                                {
                                    sessionModClient.SetCompany(soHeader.CompanyCode, out siteID, out siteName, out workstationID, out workstationDescription, out employeeID, out countryGroupCode, out countryCode, out tenantID);
                                }

                                //company = sessionModClient.GetCurrentValues(out companyName, out siteID, out siteName, out employeeID, out workstationID, out workstationDescription, out systemCode, out countryGroupCode, out countryCode, out tenantID);
                                SalesOrderTableset soTableset = new SalesOrderTableset();
                                soClient.GetNewOrderHed(ref soTableset);
                                var soHeaderRow = soTableset.OrderHed.Where(p => p.RowMod == "A").FirstOrDefault();
                                if (soHeaderRow != null)
                                {
                                    MapToHeaderRow(soHeaderRow, soHeader);
                                    soClient.Update(ref soTableset);
                                    var orderNum = soTableset.OrderHed[0].OrderNum;
                                    soHeader.Ordernum            = orderNum;
                                    soHeader.LastUpdatedDateTime = DateTime.Now;
                                    soHeader.DMSFlag             = "S";
                                    Console.WriteLine($"Added soHeader: [{soHeader.CompanyCode}]#{orderNum} successfully!");

                                    soTableset.OrderHed[0].ReadyToCalc = false;
                                    soTableset.OrderHed[0].RowMod      = "U";
                                    soClient.Update(ref soTableset);

                                    //Details
                                    var soDetails = db.SO_DETAIL.Where(c => c.DocNum == soHeader.DocNum && c.DMSFlag == "N" && c.ProductCode != "DISCOUNT" /* c.DMSFlag == "N" || c.DMSFlag == "U"*/).ToList().OrderBy(c => int.Parse(c.LineNum));
                                    foreach (var soDetail in soDetails)
                                    {
                                        try
                                        {
                                            soClient.GetNewOrderDtl(ref soTableset, orderNum);
                                            var soDetailRow = soTableset.OrderDtl.Where(p => p.RowMod == "A").FirstOrDefault();
                                            if (soDetailRow != null)
                                            {
                                                MapToDetailRow(soDetailRow, soDetail);
                                                soClient.Update(ref soTableset);
                                                soDetail.CreatedBy = soTableset.OrderDtl.Max(d => d.OrderLine).ToString();
                                                soDetail.DMSFlag   = "S";
                                                Console.WriteLine($"Added soDetail: [{soHeader.CompanyCode}]#{orderNum}/{soDetail.LineNum} successfully!");
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            soDetail.DMSFlag   = "F";
                                            soDetail.SystemLog = $"Added soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}";
                                            log.Error($"Added soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}", e.GetBaseException());
                                            Console.WriteLine($"Added soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.Message}");
                                            Console.WriteLine(e.GetBaseException().Message);
                                            continue;
                                        }
                                    }

                                    foreach (var soDetail in soDetails.Where(d => d.DMSFlag != "F"))
                                    {
                                        try
                                        {
                                            var lineNum = int.Parse(soDetail.CreatedBy);
                                            soClient.GetNewOrderRelTax(ref soTableset, orderNum, lineNum, 1, soDetail.TaxCode, soDetail.RateCode);
                                            soClient.ChangeManualTaxCalc(orderNum, lineNum, 1, soDetail.TaxCode, soDetail.RateCode, ref soTableset);
                                            Console.WriteLine($"Calculate tax soDetail: [{soHeader.CompanyCode}]#{orderNum}/{soDetail.LineNum} successfully!");
                                        }
                                        catch (Exception e)
                                        {
                                            soDetail.DMSFlag   = "F";
                                            soDetail.SystemLog = $"Calculate tax soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}";
                                            log.Error($"Calculate tax soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}", e.GetBaseException());
                                            Console.WriteLine($"Calculate tax soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.Message}");
                                            Console.WriteLine(e.GetBaseException().Message);
                                            continue;
                                        }
                                    }
                                    soClient.Update(ref soTableset);

                                    foreach (var soDetail in soDetails.Where(d => d.VATGroup != null && d.DMSFlag != "F"))
                                    {
                                        try
                                        {
                                            var lineNum     = int.Parse(soDetail.CreatedBy);
                                            var soDetailRow = soTableset.OrderDtl.FirstOrDefault(d => d.OrderLine == lineNum);
                                            soDetailRow.TaxCatID = soDetail.VATGroup;
                                            soDetailRow.RowMod   = "U";
                                            Console.WriteLine($"Updated VATGroup soDetail: [{soHeader.CompanyCode}]#{orderNum}/{soDetail.LineNum} successfully!");
                                        }
                                        catch (Exception e)
                                        {
                                            soDetail.DMSFlag   = "F";
                                            soDetail.SystemLog = $"Updated VATGroup soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}";
                                            log.Error($"Updated VATGroup soDetail:[{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}", e.GetBaseException());
                                            Console.WriteLine($"Updated VATGroup soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.Message}");
                                            Console.WriteLine(e.GetBaseException().Message);
                                            continue;
                                        }
                                    }

                                    soTableset.OrderHed[0].ReadyToCalc = true;
                                    soTableset.OrderHed[0].RowMod      = "U";
                                    soClient.Update(ref soTableset);
                                }
                            }
                            catch (Exception e)
                            {
                                soHeader.DMSFlag   = "F";
                                soHeader.SystemLog = $"Added soHeader: [{soHeader.CompanyCode}]#{soHeader.DocNum} failed! - {e.GetBaseException().Message}";
                                log.Error($"Added soHeader: [{soHeader.CompanyCode}]#{soHeader.DocNum} failed! - {e.GetBaseException().Message}", e.GetBaseException());
                                Console.WriteLine($"Added soHeader: [{soHeader.CompanyCode}]#{soHeader.DocNum} failed! - {e.Message}");
                                Console.WriteLine(e.GetBaseException().Message);
                                continue;
                            }
                        }

                        await db.SaveChangesAsync();
                    }

                    sessionModClient.Logout();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetBaseException().Message);
            }
        }