Пример #1
0
        private DataTable CargarMT(DataTable _dtDatos, DataTable _dtMT)
        {
            Cursor = Cursors.WaitCursor;
            int iCont = 0;

            try
            {
                string sMensaje = string.Empty;
                for (int row = 0; row < _dtDatos.Rows.Count; row++)
                {
                    if (string.IsNullOrEmpty(_dtDatos.Rows[row][0].ToString()))
                    {
                        continue;
                    }

                    string sUser = _dtDatos.Rows[row][0].ToString();

                    if (sUser.StartsWith("Location"))
                    {
                        continue;
                    }

                    if (sUser.StartsWith("MX03"))
                    {
                        continue;
                    }

                    string sCant = _dtDatos.Rows[row][1].ToString();

                    double dReal = 0;
                    if (!double.TryParse(sCant, out dReal))
                    {
                        dReal = 0;
                    }

                    UsuarioLogica user = new UsuarioLogica();
                    user.Usuario = sUser;
                    user.Turno   = _lsTurno;
                    if (UsuarioLogica.VerificarTurno(user))
                    {
                        DataTable dtU     = UsuarioLogica.Consultar(user);
                        string    sPlanta = dtU.Rows[0]["planta"].ToString();
                        if (sPlanta == "LAS")
                        {
                            _dtMT = GeneraReporte(sUser, dReal, _dtMT);
                            iCont++;
                        }
                    }
                    else
                    {
                        if (_lsTurno == "1")
                        {
                            Metadet2Logica met2 = new Metadet2Logica();
                            met2.Usuario = sUser;
                            met2.Real    = dReal;
                            Metadet2Logica.Guardar(met2);
                        }

                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Favor de Notificar al Administrador" + Environment.NewLine + ex.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor = Cursors.Default;
                return(_dtMT);
            }

            Cursor = Cursors.Default;
            return(_dtMT);
        }
Пример #2
0
        private void DailyProcessing()
        {
            DataTable dtData = new DataTable();

            _lsTurno = "2";
            DateTime dtTime = DateTime.Now;
            int      iHora  = dtTime.Hour;

            if (iHora >= 5 && iHora <= 16)
            {
                _lsTurno = "1";
            }

            if (iHora > 23)
            {
                iHora -= 23;
            }

            _lsHrReg = Convert.ToString(iHora).PadLeft(2, '0') + ":00";
            MetadiaLogica mdia = new MetadiaLogica();

            mdia.Hora = _lsHrReg;
            if (MetadiaLogica.Verificar(mdia))
            {
                return;
            }

            string sHrFile = DateTime.Now.Hour.ToString();

            iHora += 2;//CT zone

            if (iHora < 12)
            {
                sHrFile = iHora.ToString() + "am";
            }
            else
            {
                if (iHora > 23)
                {
                    if (iHora == 24)
                    {
                        iHora = 12;
                    }
                    else
                    {
                        iHora -= 24;
                    }
                    sHrFile = iHora.ToString() + "am";
                }
                else
                {
                    if (iHora > 12)
                    {
                        iHora -= 12;
                    }
                    sHrFile = iHora.ToString() + "pm";
                }
            }


            string sArchivo = _lsSynFile + sHrFile + ".xlsx";
            string sFile    = _lsSynURL + @"\" + sArchivo;

            if (!File.Exists(sFile))
            {
                return;
            }
            else
            {
                if (!FileLocked(sFile))
                {
                    dtData = CargarArchivo(sFile);
                }

                File.Delete(sFile);
            }
            // SAVE DATA
            if (dtData.Rows.Count > 0)
            {
                DataTable dtMt = new DataTable("Metadet");
                dtMt.Columns.Add("folio", typeof(long));
                dtMt.Columns.Add("consec", typeof(int));
                dtMt.Columns.Add("Usuario", typeof(string));
                dtMt.Columns.Add("Planta", typeof(string));
                dtMt.Columns.Add("Linea", typeof(string));
                dtMt.Columns.Add("Meta", typeof(double));
                dtMt.Columns.Add("Real", typeof(double));

                dtMt = CargarMT(dtData, dtMt);

                if (dtMt.Rows.Count > 0)
                {
                    try
                    {
                        Cursor = Cursors.WaitCursor;

                        long   lFolio    = AccesoDatos.Consec(_lsProceso);
                        double dMetaGlob = 0;
                        double dRealGlob = 0;
                        for (int x = 0; x < dtMt.Rows.Count; x++)
                        {
                            double dMeta = Convert.ToDouble(dtMt.Rows[x][5].ToString());
                            double dReal = Convert.ToDouble(dtMt.Rows[x][6].ToString());
                            dMetaGlob += dMeta;
                            dRealGlob += dReal;
                        }

                        MetadiaLogica met = new MetadiaLogica();
                        met.Folio = lFolio;
                        met.Fecha = DateTime.Today;
                        if (DateTime.Now.Hour < 5)
                        {
                            met.Fecha = DateTime.Today.AddDays(-1);
                        }
                        met.Planta  = _lsPlanta;
                        met.Turno   = _lsTurno;
                        met.Hora    = _lsHrReg;
                        met.Meta    = dMetaGlob;
                        met.Real    = dRealGlob;
                        met.Usuario = Global.gsUsuario;
                        if (MetadiaLogica.Guardar(met) == 0)
                        {
                            MessageBox.Show("Error al intentar guardar" + Environment.NewLine + "MetadiaLogica.Guardar()", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Cursor = Cursors.Default;
                            return;
                        }

                        //metadet
                        for (int x = 0; x < dtMt.Rows.Count; x++)
                        {
                            string sUsuario = dtMt.Rows[x][2].ToString();
                            string sPlanta  = dtMt.Rows[x][3].ToString();
                            string sLinea   = dtMt.Rows[x][4].ToString();
                            double dMeta    = Convert.ToDouble(dtMt.Rows[x][5].ToString());
                            double dReal    = Convert.ToDouble(dtMt.Rows[x][6].ToString());
                            if (dMeta == 0)
                            {
                                dMeta = dReal;
                            }

                            if (_lsTurno == "2")
                            {
                                Metadet2Logica met2 = new Metadet2Logica();
                                met2.Usuario = sUsuario;

                                DataTable dtAnt = Metadet2Logica.Consultar(met2);
                                if (dtAnt.Rows.Count > 0)
                                {
                                    double dRealAnt = double.Parse(dtAnt.Rows[0][3].ToString());
                                    dReal -= dRealAnt;
                                }
                            }

                            string        sRamp   = string.Empty;
                            double        dRampeo = 0;
                            UsuarioLogica user    = new UsuarioLogica();
                            user.Usuario = sUsuario;
                            DataTable dtU = UsuarioLogica.Consultar(user);
                            sRamp = dtU.Rows[0]["ind_ramp"].ToString();
                            if (sRamp == "1")
                            {
                                dRampeo = double.Parse(dtU.Rows[0]["rampeo"].ToString());
                            }

                            if (dRampeo > 0)
                            {
                                dRampeo = dRampeo / 100;
                                double dRa = dMeta * dRampeo;
                                dMeta = dMeta - dRa;
                            }
                            if (dReal < 0)
                            {
                                dReal = 0;
                            }

                            double dPorc = dReal / dMeta;
                            if (dPorc < 0)
                            {
                                dPorc = 0;
                            }
                            dPorc = dPorc * 100;

                            MetadetLogica med = new MetadetLogica();
                            med.Folio   = lFolio;
                            med.Consec  = 0;
                            med.Usuario = sUsuario;
                            med.Planta  = sPlanta;
                            med.Linea   = sLinea;
                            med.Meta    = dMeta;
                            med.Real    = dReal;
                            med.Porcen  = Math.Round(dPorc, 2);

                            if (MetadetLogica.Guardar(med) == 0)
                            {
                                MessageBox.Show("Error al intentar guardar la Linea", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                Cursor = Cursors.Default;
                                return;
                            }
                        }
                        Cursor = Cursors.Default;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Favor de notificar al Administrador" + Environment.NewLine + ex.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }
            }
        }