Exemplo n.º 1
0
        private void btnResetPO_Click(object sender, RoutedEventArgs e)
        {
            //This is ugly for now but I am in a hurry to get this functionality
            var po = Microsoft.VisualBasic.Interaction.InputBox("P/O:", "Reset a P/O to show as not sent to COINS");

            using (ApexDataDataContext apexData = new ApexDataDataContext(_SqlConnBuilder.ConnectionString))
            {
                PO apexPO = apexData.POs.Where(s => s.Po1 == po.PadLeft(12)).SingleOrDefault();
                if (apexPO == null)
                {
                    MessageBox.Show("P/O not found", "Unable to Reset P/O", MessageBoxButton.OK);
                    return;
                }
                else
                {
                    apexPO.ExpBatch = -1;
                    apexPO.ExpSent  = "F";
                    apexData.SubmitChanges();

                    apexData.ExecuteCommand("DELETE FROM COINSESB_ExpL WHERE PO = '" + apexPO.Po1 + "'");
                    MessageBox.Show("P/O reset as requested", "Reset Successful", MessageBoxButton.OK);
                }
            }
        }
Exemplo n.º 2
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     grdExpL.View.CommitEditing();
     dc.SubmitChanges();
 }
Exemplo n.º 3
0
        private async Task ProcessPO(PO porec, ApexDataDataContext apexData)
        {
            ProgressInfo.Add($"Sending P/O {porec.Po1.Trim()}");

            string reportMessage;

            ApexSystem apexSystem = apexData.ApexSystems.FirstOrDefault();

            COINSESBService.COINSInterfaceHeader    header;
            COINSESBService.COINSInterfacePo_hdrRow poheader;

            header = new COINSESBService.COINSInterfaceHeader
            {
                id          = (apexSystem.ExportBatch ?? 1).ToString(),
                confirm     = COINSESBService.COINSInterfaceHeaderConfirm.no,
                UserID      = "pkramer",
                From        = "Apex",
                HostName    = "coinsoa",
                Environment = "live",
                Created     = DateTime.UtcNow,
                Login       = new COINSESBService.COINSInterfaceHeaderLogin()
                {
                    User     = "******",
                    Password = "******",
                    CID      = 1
                }
            };

            if (!String.IsNullOrEmpty(porec.Job)) //Job based P/O
            {
                poheader = BuildJobBasedPOHeader(porec, apexSystem);

                poheader.po_lineRow = new COINSESBService.COINSInterfacePo_hdrRowPo_lineRow[porec.POLines.Count];

                for (int i = 0; i < porec.POLines.Count; i++)
                {
                    POLine polinerec = porec.POLines[i];

                    string jobphase = String.IsNullOrEmpty(porec.JobPhase) ? "00" : porec.JobPhase;
                    string wbs;

                    COINSESB_WB wbsRec = apexData.COINSESB_WBs.Where(s => s.Job == porec.Job).FirstOrDefault();
                    if (wbsRec == null || !(wbsRec.UsesActivity ?? false))
                    {
                        wbs = jobphase + "-";
                    }
                    else
                    {
                        wbs = jobphase + "-00-";
                    }

                    COINSESB_ExpL expL      = apexData.COINSESB_ExpLs.Where(s => s.PO == polinerec.Po && s.POLine == polinerec.PoLine1).SingleOrDefault();
                    int?          pol_seq   = expL?.POL_Seq;
                    decimal?      lastPrice = expL?.LastPrice;

                    string cat      = "MA";
                    string schedule = "STD";
                    Job    job      = apexData.Jobs.Where(s => s.Job1 == porec.Job).FirstOrDefault();
                    if (job != null)
                    {
                        schedule = job.Schedule;
                        Costcode ccd = apexData.Costcodes.Where(s => s.Schedule == schedule && s.CostCode1 == polinerec.CostCode).FirstOrDefault();
                        if (ccd != null)
                        {
                            cat = ccd.GL;
                        }
                    }

                    COINSESBService.COINSInterfacePo_hdrRowPo_lineRow
                        polinerow = BuildJobBasedPOLine(polinerec, wbs, pol_seq, cat,
                                                        expL != null && ((polinerec.Price ?? 0) != (lastPrice ?? 0)), porec.ShipDate ?? DateTime.Now);
                    poheader.po_lineRow[i] = polinerow;
                }
            }
            else //Work Order based P/O
            {
                poheader = BuildWOBasedPOHeader(porec, apexSystem);

                poheader.po_lineRow = new COINSESBService.COINSInterfacePo_hdrRowPo_lineRow[porec.POLines.Count];

                for (int i = 0; i < porec.POLines.Count; i++)
                {
                    POLine polinerec = porec.POLines[i];

                    COINSESB_ExpL expL      = apexData.COINSESB_ExpLs.Where(s => s.PO == polinerec.Po && s.POLine == polinerec.PoLine1).SingleOrDefault();
                    int?          pol_seq   = expL?.POL_Seq;
                    decimal?      lastPrice = expL?.LastPrice;

                    string   cat      = "MA";
                    string   schedule = "STD";
                    Costcode ccd      = apexData.Costcodes.Where(s => s.Schedule == schedule && s.CostCode1 == polinerec.CostCode).FirstOrDefault();
                    if (ccd != null)
                    {
                        cat = ccd.GL;
                    }

                    COINSESBService.COINSInterfacePo_hdrRowPo_lineRow
                        polinerow = BuildWOBasedPOLine(porec, polinerec, pol_seq, cat,
                                                       expL != null && ((polinerec.Price ?? 0) != (lastPrice ?? 0)), porec.ShipDate ?? DateTime.Now);
                    poheader.po_lineRow[i] = polinerow;
                }
            }

            COINSESBService.COINSInterfacePo_hdrRow[] poheaderrows = new COINSESBService.COINSInterfacePo_hdrRow[1];
            poheaderrows[0] = poheader;

            var client        = new COINSESBService.COINSInterfacePortClient("COINSInterface");
            var actionrequest = new COINSESBService.doActionRequest
            {
                Header = header,
                Body   = poheaderrows
            };

#if SENDXMLDIAGNOSTIC
            XmlSerializer serializer = new XmlSerializer(typeof(COINSESBService.doActionRequest));
            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, actionrequest);
                stream.Seek(0, SeekOrigin.Begin);
                string     capturedXML  = stream.ReadToString();
                HttpClient postClient   = new HttpClient();
                var        postResponse = await postClient.PostAsync("http://apexcoin.apexpurchasing.com/api/coinsxml",
                                                                     new StringContent(capturedXML));
            }
#endif

            var response = await client.doActionAsync(actionrequest);

            if (response.Header.action == COINSESBService.COINSInterfaceResponseHeaderAction.RESPONSE)
            {
                if (porec.ExpSent == "T")
                {
                    reportMessage = "Sent to COINS (Amendment)";
                }
                else
                {
                    reportMessage = "Sent to COINS";
                }

                porec.ExpSent = "T";
                var lines         = response.Body.po_hdrRow[0].po_lineRow;
                int lineRowNumber = 0;
                foreach (var POLine in porec.POLines)
                {
                    var  pol_seq   = lines[lineRowNumber++].pol_seq;
                    bool newRecord = false;
                    var  expL      = apexData.COINSESB_ExpLs.Where(s => s.PO == POLine.Po && s.POLine == POLine.PoLine1).SingleOrDefault();
                    if (expL == null)
                    {
                        expL = new COINSESB_ExpL
                        {
                            PO     = POLine.Po,
                            POLine = POLine.PoLine1
                        };
                        newRecord = true;
                    }

                    expL.POL_Seq   = pol_seq;
                    expL.LastAmt   = POLine.Ext;
                    expL.LastPrice = POLine.Price;
                    if (newRecord)
                    {
                        apexData.COINSESB_ExpLs.InsertOnSubmit(expL);
                    }
                    apexData.SubmitChanges();
                }
            }
            else if (response.Header.action == COINSESBService.COINSInterfaceResponseHeaderAction.EXCEPTION)
            {
                reportMessage = response.Body.Exception.Exception;
            }
            else
            {
                reportMessage = "Unknown response from COINS";
            }

            porec.ExpBatch          = apexSystem.ExportBatch ?? 1;
            apexSystem.ExportBatch += 1;
            apexData.SubmitChanges();

            _StatusLines.Add(new StatusLine
            {
                PO      = porec.Po1?.Trim(),
                Job     = porec.Job?.Trim(),
                WorkOrd = porec.WorkOrd?.Trim(),
                Vendor  = porec.Vendor?.Trim(),
                Message = reportMessage
            });
        }