Пример #1
0
        private MigrazioneODLDS.USR_PRD_MOVFASIRow estraiDatiODLAuto(string ordine)
        {
            using (MigrazioneODLBusiness bMigrazioneODLAuto = new MigrazioneODLBusiness())
            {
                bMigrazioneODLAuto.GetUSR_PRD_MOVFASI(_ds, ordine);


                MigrazioneODLDS.USR_PRD_MOVFASIRow odls = _ds.USR_PRD_MOVFASI.Where(x => x.BARCODE == ordine).FirstOrDefault();
                if (odls != null)
                {
                    bMigrazioneODLAuto.GetCLIFO(_ds, odls.CODICECLIFO);
                    MigrazioneODLDS.CLIFORow reparto = _ds.CLIFO.Where(x => x.CODICE == odls.CODICECLIFO).FirstOrDefault();

                    bMigrazioneODLAuto.GetTABFAS(_ds, odls.IDTABFAS);
                    MigrazioneODLDS.TABFASRow fase = _ds.TABFAS.Where(x => x.IDTABFAS == odls.IDTABFAS).FirstOrDefault();

                    bMigrazioneODLAuto.GetMAGAZZ(_ds, odls.IDMAGAZZ);
                    MigrazioneODLDS.MAGAZZRow articolo = _ds.MAGAZZ.Where(x => x.IDMAGAZZ == odls.IDMAGAZZ).FirstOrDefault();

                    txtIDPRDMOVFASE.Text = odls.IDPRDMOVFASE;
                    txtAZIENDA.Text      = odls.AZIENDA;
                    txtREPARTO.Text      = reparto.RAGIONESOC.Trim();
                    txtFASE.Text         = fase.CODICEFASE.Trim();
                    txtIDMAGAZZ.Text     = articolo.IDMAGAZZ.Trim();
                    txtArticolo.Text     = articolo.MODELLO.Trim();
                    txtQuantita.Text     = odls.QTA.ToString();
                    txtQtaDaTer.Text     = odls.QTADATER.ToString();
                    txtMetodoDiba.Text   = odls.IDDIBAMETHOD;
                    txtVersioneDiba.Text = odls.VERSION.ToString();
                    txtDescVersione.Text = odls.DESVERSION.Trim();
                    txtDescVersione.Text = odls.NUMMOVFASE;
                    txtNumOdl.Text       = odls.NUMMOVFASE;
                }
                return(odls);
            }
        }
Пример #2
0
        private void _bgwMigraODL_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            string           numord = txtBarcodeODL.Text;

            ODLDTO dto = (ODLDTO)e.Argument;

            int progress = 1;

            foreach (string nummovfase in dto.odls)
            {
                decimal perc = progress;

                string distintaBC = string.Empty;
                worker.ReportProgress((int)perc);
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                try
                {
                    MigrazioneODLDS ds = new MigrazioneODLDS();

                    if (string.IsNullOrEmpty(nummovfase))
                    {
                        continue;
                    }
                    //string anagraficaBC = string.Empty;
                    MigrazioneODLDS.USR_PRD_MOVFASIRow odl      = null;
                    MigrazioneODLDS.MAGAZZRow          articolo = null;
                    string desvcrizione2odl       = string.Empty;
                    string descrizioneVersioneODV = string.Empty;
                    string repartoRagSoc          = string.Empty;
                    string faseCodice             = string.Empty;

                    using (MigrazioneODLBusiness bMigrazioneODL = new MigrazioneODLBusiness())
                    {
                        bMigrazioneODL.InsertODL2ODPlog(nummovfase, "8 Migrazione iniziata", dto.esecuzione, dto.company);

                        bMigrazioneODL.GetUSR_PRD_MOVFASIByNumdoc(ds, nummovfase);
                        odl = ds.USR_PRD_MOVFASI.Where(x => x.NUMMOVFASE == nummovfase).FirstOrDefault();

                        if (odl == null)
                        {
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, "1 ODL NON TROVATO", dto.esecuzione, dto.company);
                            continue;
                        }

                        bMigrazioneODL.GetCLIFO(ds, odl.CODICECLIFO);
                        MigrazioneODLDS.CLIFORow reparto = ds.CLIFO.Where(x => x.CODICE == odl.CODICECLIFO).FirstOrDefault();
                        repartoRagSoc = reparto.CODICE;

                        if (reparto.CODICE.Substring(0, 1) == "0")
                        {
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, "7 REPARTO TERZISTA", dto.esecuzione, dto.company);
                            continue;
                        }

                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        bMigrazioneODL.GetTABFAS(ds, odl.IDTABFAS);
                        MigrazioneODLDS.TABFASRow fase = ds.TABFAS.Where(x => x.IDTABFAS == odl.IDTABFAS).FirstOrDefault();
                        faseCodice = fase.CODICEFASE;

                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        bMigrazioneODL.GetMAGAZZ(ds, odl.IDMAGAZZ);
                        articolo = ds.MAGAZZ.Where(x => x.IDMAGAZZ == odl.IDMAGAZZ).FirstOrDefault();

                        bool continua = true;
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }
                        MigrazioneODLDS.BC_ANAGRAFICA_PRODUZIONERow anagrafica = bMigrazioneODL.GetANAGRAFICA(ds, odl.IDMAGAZZ);

                        MigrazioneODLDS.USR_PRD_FASIRow prdFase = bMigrazioneODL.GetUSR_PRD_FASI(ds, odl.IsIDPRDFASENull() ? string.Empty : odl.IDPRDFASE, odl.AZIENDA);
                        if (prdFase == null && anagrafica == null)
                        {
                            string str = string.Format("2 USR PRD FASE non trovata ");
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, str, dto.esecuzione, dto.company);
                            continue;
                        }
                        while (anagrafica == null && continua)
                        {
                            if (prdFase.IsIDPRDFASEPADRENull() || string.IsNullOrEmpty(prdFase.IDPRDFASEPADRE))
                            {
                                string str = string.Format("9 impossibile trovare una anagrafica di trasferimento idmagazz {0} odl {1}", odl.IDMAGAZZ, odl.IDPRDMOVFASE);
                                bMigrazioneODL.InsertODL2ODPlog(nummovfase, str, dto.esecuzione, dto.company);
                                continua = false;
                                continue;
                            }
                            prdFase = bMigrazioneODL.GetUSR_PRD_FASI(ds, prdFase.IDPRDFASEPADRE, prdFase.AZIENDA);
                            if (prdFase != null)
                            {
                                anagrafica = bMigrazioneODL.GetANAGRAFICA(ds, prdFase.IDMAGAZZ);
                            }
                            else
                            {
                                string str = string.Format("3 fase padre non trovata ");
                                bMigrazioneODL.InsertODL2ODPlog(nummovfase, str, dto.esecuzione, dto.company);
                                continua = false;
                            }
                        }

                        if (anagrafica == null)
                        {
                            string str = string.Format("4 Anagrafica non trovata ");
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, str, dto.esecuzione, dto.company);
                            continue;
                        }

                        distintaBC = anagrafica.BC;

                        descrizioneVersioneODV = string.Format("{0} {1}", odl.NUMMOVFASE, odl.DATAMOVFASE.ToShortDateString());
                        desvcrizione2odl       = string.Format("{0} - {1}", reparto.CODICE.Trim(), fase.CODICEFASE.Trim());
                    }

                    if (odl == null)
                    {
                        continue;
                    }
                    if (articolo == null)
                    {
                        continue;
                    }

                    string  IDPRDMOVFASE = odl.IDPRDMOVFASE;
                    string  azienda      = odl.AZIENDA;
                    string  idmagazz     = articolo.IDMAGAZZ.Trim();
                    string  modello      = articolo.MODELLO.Trim();
                    decimal quantita     = odl.QTA;
                    decimal qtadater     = odl.QTADATER;


                    using (MigrazioneODLSQLBusiness bMigrazioneODLSQL = new MigrazioneODLSQLBusiness())
                    {
                        bMigrazioneODLSQL.GetDistinteBCDettaglio(ds, distintaBC);
                    }
                    using (MigrazioneODLBusiness bMigrazioneODL = new MigrazioneODLBusiness())
                    {
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        MPIntranet.WS.BCServices bc = new MPIntranet.WS.BCServices();
                        bc.CreaConnessione(dto.company);

                        bMigrazioneODL.GetODL2ODP(ds, nummovfase);
                        bMigrazioneODL.GetODL2ODPCOMPONENTI(ds, nummovfase);

                        List <MigrazioneODLDS.ODL2ODPRow> odls = ds.ODL2ODP.Where(x => x.NUMMOVFASE == nummovfase && x.COMPANY == dto.company).ToList();
                        if (odls.Count > 0)
                        {
                            MigrazioneODLDS.ODL2ODPRow odp = odls[0];
                            string msg = String.Format("5 ODL già migrato nell'ordine di produzione {0} per la company {1}", odp.ODV, dto.company);
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, msg, dto.esecuzione, dto.company);
                            continue;
                        }

                        List <MigrazioneODLDS.ODL2ODPCOMPONENTIRow> odlsComp = ds.ODL2ODPCOMPONENTI.Where(x => x.NUMMOVFASE == nummovfase && x.COMPANY == dto.company).ToList();
                        if (odlsComp.Count > 0)
                        {
                            string msg = String.Format("6 Componenti dell'ODL {0} già a sistema per la company {1}", txtNumOdl.Text, dto.company);
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, msg, dto.esecuzione, dto.company);
                            continue;
                        }
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        if (dto.soloRVL)
                        {
                            bMigrazioneODL.InsertODL2ODPlog(nummovfase, "0 Migrazione completata correttamente SOLO RVL", dto.esecuzione, dto.company);
                            continue;
                        }
                        string codiceODP = bc.CreaOdDPConfermato(distintaBC, DateTime.Now, quantita, ubicazione, descrizioneVersioneODV, desvcrizione2odl);
                        bMigrazioneODL.InsertODL2ODP(azienda, odl.IDPRDMOVFASE, nummovfase, repartoRagSoc.Trim(), faseCodice, idmagazz, distintaBC, quantita, codiceODP, descrizioneVersioneODV, desvcrizione2odl, dto.company);

                        int             linenumber = 0;
                        List <RegMesWS> magazzino  = bc.EstraiRegMag();
                        if (magazzino.Count > 0)
                        {
                            linenumber = magazzino.Where(x => x.Journal_Batch_Name == "REGWS").Max(x => x.Line_No);
                        }

                        foreach (MigrazioneODLDS.DistinteBCDettaglioRow dettaglio in ds.DistinteBCDettaglio.Where(x => x.Production_BOM_No_ == distintaBC))
                        {
                            decimal quantitaComponente = quantita * dettaglio.Quantity;
                            linenumber += 1000;
                            bc.CreaRegistrazioneMagazzino(ubicazione, collocazione, linenumber, nummovfase, quantitaComponente, dettaglio.No_);
                            bMigrazioneODL.InsertODL2ODPComponenti(azienda, nummovfase, repartoRagSoc.Trim(), faseCodice, distintaBC, dettaglio.No_, quantitaComponente, quantita, codiceODP, ubicazione, collocazione, dto.company);
                        }
                        if (dto.ChBoxRegMag)
                        {
                            bc.PostingRegMag();
                        }

                        bMigrazioneODL.InsertODL2ODPlog(nummovfase, "0 Migrazione completata correttamente", dto.esecuzione, dto.company);
                    }
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("ECCEZIONE ");
                    while (ex != null)
                    {
                        sb.AppendLine(ex.Message);
                        sb.AppendLine(ex.Source);
                        ex = ex.InnerException;
                        sb.AppendLine("**");
                    }
                    using (MigrazioneODLBusiness bMigrazioneODL = new MigrazioneODLBusiness())
                    {
                        bMigrazioneODL.InsertODL2ODPlog(nummovfase, sb.ToString(), dto.esecuzione, dto.company);
                    }
                }
                finally
                {
                    progress++;
                }
            }
        }