コード例 #1
0
        private bool trovaAnagraficaPerMigrazione(MigrazioneODLDS.USR_PRD_MOVFASIRow odl)
        {
            txtAnagrafica.Text = string.Empty;
            if (odl.IsIDMAGAZZNull())
            {
                return(false);
            }


            string idmagazz = odl.IDMAGAZZ;

            using (MigrazioneODLBusiness bMigrazioneODL = new MigrazioneODLBusiness())
            {
                bool continua = true;
                MigrazioneODLDS.BC_ANAGRAFICA_PRODUZIONERow anagrafica = bMigrazioneODL.GetANAGRAFICA(_ds, idmagazz);

                if (anagrafica != null)
                {
                    txtAnagrafica.Text = (anagrafica == null) ? string.Empty : anagrafica.BC;
                    return(true);
                }
                bMigrazioneODL.FillBC_MIGRAZIONE(_ds);
                MigrazioneODLDS.BC_MIGRAZIONERow riga = _ds.BC_MIGRAZIONE.Where(x => x.IDMAGAZZ == idmagazz).FirstOrDefault();
                if (riga == null)
                {
                    return(false);
                }
                decimal iddiba = riga.DIBA;
                decimal idnodo = riga.IDNODO;
                while (anagrafica == null && continua)
                {
                    riga = _ds.BC_MIGRAZIONE.Where(x => x.IDNODO == idnodo && x.DIBA == iddiba).FirstOrDefault();
                    if (riga == null)
                    {
                        continua = false;
                    }
                    else
                    {
                        if (riga.IDPADRE < 0)
                        {
                            continua = false;
                        }
                        else
                        {
                            MigrazioneODLDS.BC_MIGRAZIONERow rigaPadre = _ds.BC_MIGRAZIONE.Where(x => x.IDNODO == riga.IDPADRE && x.DIBA == iddiba).FirstOrDefault();
                            idmagazz   = rigaPadre.IDMAGAZZ;
                            idnodo     = rigaPadre.IDNODO;
                            anagrafica = bMigrazioneODL.GetANAGRAFICA(_ds, idmagazz);
                        }
                    }
                }

                txtPRODOTTOFINITO.Text = riga.PRODOTTOFINALE;
                txtAnagrafica.Text     = (anagrafica == null) ? string.Empty : anagrafica.BC;

                return(anagrafica != null);
            }
        }
コード例 #2
0
        public MigrazioneODLDS.BC_ANAGRAFICA_PRODUZIONERow GetANAGRAFICA(MigrazioneODLDS ds, String idmagazz)
        {
            MigrazioneODLDS.BC_ANAGRAFICA_PRODUZIONERow anagrafica = ds.BC_ANAGRAFICA_PRODUZIONE.Where(x => x.IDMAGAZZ == idmagazz).FirstOrDefault();

            if (anagrafica != null)
            {
                return(anagrafica);
            }

            MigrazioneODLAdapter a = new MigrazioneODLAdapter(DbConnection, DbTransaction);

            a.GetANAGRAFICA(ds, idmagazz);
            return(ds.BC_ANAGRAFICA_PRODUZIONE.Where(x => x.IDMAGAZZ == idmagazz).FirstOrDefault());
        }
コード例 #3
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++;
                }
            }
        }