Esempio n. 1
0
 public static void UpdatePbar(System.Windows.Forms.ProgressBar name, int step)
 {
     if (name.InvokeRequired)
     {
         object[] params_list = new object[] { name, step };
         name.Invoke(new UpdateProgressBar(UpdatePbar), params_list);
     }
     else { name.Increment(step); }
 }
Esempio n. 2
0
 private void DelgateDeclarationProgInc(System.Windows.Forms.ProgressBar myctl, int i)
 {
     myctl.Increment(i);
 }
Esempio n. 3
0
        public static bool Import(String filePath, IEstado estado, System.Windows.Forms.ProgressBar progress = null, System.Windows.Forms.Label lblprogress = null, bool raiseErrorFileAlreadyImp = true)
        {
            // verifica se arquivo já foi importado
            string md5 = Cryptography.Files.MD5.GetMD5Hash(filePath);
            IList<ILogIBPT> log = new LogIBPT()
                                            .Find<ILogIBPT>(new Where()
                                            {
                                                {
                                                    "sis_logibpt.md5", md5
                                                }
                                            });
            if (log.Count != 0 && raiseErrorFileAlreadyImp)
                throw new ArquivoJaImportado();

            // verifica se arquivo é do mesmo estado da empresa
            String stateEmp = estado.UF.Sigla;
            String stateFile = filePath.Split('\\')
                                        .Last().Substring(12, 2);
            if (!stateEmp.Equals(stateFile))
                throw new EstadoInvalido();

            Connection connection = null;
            int linhas = 0;
            try
            {
                connection = DbContext.CreateConnection();
                connection.BeginTransaction();

                // Abre arquivo para importação
                INCM ncm = null;
                IList<INCM> ncms = new NCM().Find<INCM>();
                String line = null;
                if (progress != null &&
                    lblprogress != null)
                {
                    progress.Maximum = File.ReadAllLines(filePath).Length;
                    progress.Step = 1;
                    lblprogress.Visible = true;
                    lblprogress.Text = string.Format("{0}% Concluído", (100 * progress.Value) / progress.Maximum);
                    lblprogress.Refresh();
                }
                using (StreamReader str = new StreamReader(filePath, Encoding.Default))
                {

                    while ((line = str.ReadLine()) != null)
                    {
                        string[] sections = line.Split(';');

                        if (linhas == 0 || !String.IsNullOrEmpty(sections[1]))
                        {
                            linhas++;
                            if (progress != null &&
                                lblprogress != null)
                            {
                                progress.Increment(1);
                                lblprogress.Text = string.Format("{0}% Concluído", (100 * progress.Value) / progress.Maximum);
                                lblprogress.Refresh();
                            }
                            continue;
                        }
                        ncm = ncms.FirstOrDefault(w => w.NCM.Trim() == sections[0]);
                        if (ncm == null) ncm = new NCM();

                        ncm.NCM = sections[0];
                        ncm.IPI = 0;
                        ncm.II = 0;
                        ncm.Descricao = sections[3];
                        ncm.ImpostoAproxEstadual = Unimake.Convert.ToDouble(sections[6]);
                        ncm.ImpostoAproximado = Unimake.Convert.ToDouble(sections[6]);
                        ncm.ImpostoAproxImport = Unimake.Convert.ToDouble(sections[5]);
                        ncm.ImpostoAproxMunicip = Unimake.Convert.ToDouble(sections[7]);
                        ncm.ChaveIBPT = sections[10];
                        ncm.Save();
                        linhas++;
                        if (progress != null &&
                            lblprogress != null)
                        {
                            progress.Increment(1);
                            progress.Refresh();
                            lblprogress.Text = string.Format("{0}% Concluído", (100 * progress.Value) / progress.Maximum);
                            lblprogress.Refresh();
                        }
                    }
                }

                if (progress != null &&
                            lblprogress != null)
                {
                    lblprogress.Text = "Arquivo importado com sucesso!";
                    lblprogress.Refresh();

                }
                LogIBPT.Save(new LogIBPT()
                {
                    Evento = "Importação de arquivos de NCM",
                    TipoEvento = Enuns.TipoEvento.Import,
                    Caminho = filePath,
                    MD5 = md5
                });
                connection.CommitTransaction();
            }
            catch
            {
                if (connection != null)
                    connection.RollbackTransaction();

                if (progress != null &&
                           lblprogress != null)
                {
                    lblprogress.Text = "Ocorreu algum erro durante a importação!";
                    lblprogress.Refresh();
                }

                throw;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }
            return true;
        }
Esempio n. 4
0
        public static IDictionary<IActivity, IList<PointInfo[]>> findSimilarPoints(IGPSRoute refRoute, IActivityLaps refLaps, IList<IActivity> activities, System.Windows.Forms.ProgressBar progressBar)
        {
            GPSGrid refGrid = new GPSGrid(null, refRoute, 1F, 0.5F, true);
            IDictionary<IActivity, IList<PointInfo[]>> result = new Dictionary<IActivity, IList<PointInfo[]>>();
            double cumulativeAverageDist = 0;
            int noCumAv = 0;
            if (activities != null)
            {
                if (progressBar != null)
                {
                    progressBar.Value = 0;
                    progressBar.Minimum = 0;
                    progressBar.Maximum = activities.Count;
                }
                foreach (IActivity otherActivity in activities)
                {
                    const int ExtraGridIndex = 2;
                    const float MaxDistDiffFactor = 0.1F;
                    double minDistStretch = Settings.Radius * 2;

                    result.Add(otherActivity, new List<PointInfo[]>());
                    IDistanceDataTrack distTrack = otherActivity.GPSRoute.GetDistanceMetersTrack();
                    int lastMatch = -1; //index of previous match
                    int startMatch = -1;
                    IndexDiffDist lastMatchRef = null;
                    IndexDiffDist startMatchRef = null;
                    IndexDiffDist lastIndex = null;
                    for (int i = 0; i < otherActivity.GPSRoute.Count; i++)
                    {
                        IList<IndexDiffDist> currIndex = new List<IndexDiffDist>();
                        IndexDiffDist closeIndex = null; //Closest to current point
                        IndexDiffDist nextIndex = null; //The best match in this stretch
                        bool isEnd = true; //This is the end of a stretch, unless a matching point is found
                        currIndex = refGrid.getAllCloseStretch(otherActivity.GPSRoute[i].Value);
                        if (currIndex.Count > 0)
                        {
                            int prio = int.MaxValue;
                            foreach (IndexDiffDist IndDist in currIndex)
                            {
                                if (IndDist.Index > -1)
                                {
                                    //Get the closest good enough point - used at start and could restart current stretch
                                    if (closeIndex == null ||
                                        //Close match in distance
                                        (Math.Abs(IndDist.Dist - distTrack[i].Value) < 3 * Settings.Radius) ||
                                        //Close to other matches
                                        (Math.Abs(IndDist.Dist - distTrack[i].Value - cumulativeAverageDist) <
                                    Math.Abs(closeIndex.Dist - distTrack[i].Value - cumulativeAverageDist)))
                                    {
                                        closeIndex = IndDist;
                                    }

                                    //next in relation to previous match
                                    if (lastMatch > -1 && lastIndex != null)
                                    {
                                        //Only check forward, i.e follow the same direction
                                        //Use a close enough stretch
                                        //This is the iffiest part of the algorithm matching stretches...
                                        if ((IndDist.low >= lastIndex.low && IndDist.low <= lastIndex.high ||
                                             IndDist.Index >= lastIndex.low && IndDist.Index <= lastIndex.high) &&
                                            IndDist.Index >= lastIndex.Index)
                                        {
                                            //The grid overlaps the old grid
                                            //The matching index may be lower then this is a restart (this or prev match should then be dropped)
                                            if ((prio > 0 && (nextIndex == null || IndDist.Diff < nextIndex.Diff) && IndDist.Index >= lastIndex.Index))
                                            {
                                                nextIndex = IndDist;
                                                prio = 0;
                                            }
                                            else if (prio >= 0 && (IndDist.Index > lastIndex.Index && (nextIndex == null || nextIndex.Index <= lastIndex.Index)))
                                            {
                                                nextIndex = IndDist;
                                                prio = 0;
                                            }
                                            else if (IndDist.Index == lastIndex.Index && (nextIndex == null || nextIndex.Index < lastIndex.Index))
                                            {
                                                nextIndex = IndDist;
                                                prio = 0;
                                            }
                                            else if (prio > 10)
                                            {
                                                nextIndex = IndDist;
                                                prio = 10;
                                            }
                                            else if (nextIndex == null)
                                            {
                                                nextIndex = IndDist;
                                                prio = 10;
                                            }
                                            //else - not better
                                        }
                                        else if ((
                                             IndDist.low >= lastIndex.low && IndDist.low <= lastIndex.high + ExtraGridIndex ||
                                             IndDist.Index >= lastIndex.low && IndDist.Index <= lastIndex.high + ExtraGridIndex))
                                        {
                                            //Grids are not overlapping, but adjacent points match forward
                                            if (prio > 20 && IndDist.Index > lastIndex.Index)
                                            {
                                                nextIndex = IndDist;
                                                prio = 20;
                                            }
                                            else if (prio >= 20)
                                            {
                                                nextIndex = IndDist;
                                                prio = 20;
                                            }
                                        }
                                        else if ((
                                              Math.Abs(IndDist.Dist / lastIndex.Dist - 1) < MaxDistDiffFactor) &&
                                            (prio > 20))
                                        {
                                            nextIndex = IndDist;
                                            prio = 30;
                                        }
                                    }
                                }
                            }

                            //Update if close enough
                            if (closeIndex != null)
                            {
                                //TODO: This algorithm needs to prio correct direction better
                                //nextInd is best match for the stretch, but closeIndex could be better 
                                if (nextIndex == null ||
                                    (!nextIndex.Equals(closeIndex)) && (
                                    //back match - prefer closer
                                    lastIndex.Index > nextIndex.Index ||
                                    prio > 10 && (minDistStretch < distTrack[i].Value - distTrack[startMatch].Value ||
                                            (Math.Abs(nextIndex.Dist - distTrack[i].Value) > Settings.Radius) ||
                                            (Math.Abs(nextIndex.Dist - distTrack[i].Value - cumulativeAverageDist) >
                                        Math.Abs(closeIndex.Dist - distTrack[i].Value - cumulativeAverageDist)))))
                                {
                                    //switch to closeIndex and ignore nextIndex
                                    nextIndex = closeIndex;
                                    //start of new stretch - use best match to reference activity
                                    startMatch = i;
                                    lastIndex = closeIndex;
                                    startMatchRef = closeIndex;
                                }
                                else
                                {
                                    //The stretch continues
                                    isEnd = false;
                                    cumulativeAverageDist += (lastIndex.Diff - distTrack[i].Value - cumulativeAverageDist) / ++noCumAv;
                                }
                            }
                        }
                        if (isEnd && lastMatch >= 0)
                        {
                            // end match
                            PointInfo[] s = new PointInfo[2];
                            s[0] = new PointInfo(-i - 1);
                            s[1] = new PointInfo(-lastMatchRef.Index - 1);
                            result[otherActivity].Add(s);
                        }
                        if (nextIndex != null)
                        {
                            lastIndex = nextIndex;
                            lastMatchRef = lastIndex;
                            lastMatch = i;

                            PointInfo[] s = new PointInfo[2];
                            s[0] = new PointInfo(i, distTrack[i].Value, otherActivity.GPSRoute[i].ElapsedSeconds,
                                getRestLap(i, otherActivity),
                                startMatch + " " + lastMatch + " " + startMatchRef + " " + lastMatchRef);
                            s[1] = new PointInfo(lastIndex.Index, lastIndex.Dist, refRoute[lastIndex.Index].ElapsedSeconds,
                                getRestLap(lastIndex.Index, refRoute, refLaps));
                            result[otherActivity].Add(s);
                        }
                        else
                        {
                            lastMatch = -1;
                        }
                    }
                    //add end marker if needed
                    if (lastMatch > -1)
                    {
                        PointInfo[] s = new PointInfo[2];
                        s[0] = new PointInfo(-otherActivity.GPSRoute.Count);
                        s[1] = new PointInfo(-1);
                        result[otherActivity].Add(s);
                    }
                    if (progressBar != null)
                    {
                        progressBar.Increment(1);
                    }
                }
            }

            return result;
        }
Esempio n. 5
0
        public static IDictionary<IActivity, PointInfo[]> getCommonSpeed(IDictionary<IActivity, IList<PointInfo[]>> points, IList<IActivity> activities, bool useActive, System.Windows.Forms.ProgressBar progressBar)
        {
            IDictionary<IActivity, PointInfo[]> result = new Dictionary<IActivity, PointInfo[]>();
            if (progressBar != null)
            {
                progressBar.Value = 0;
                progressBar.Minimum = 0;
                progressBar.Maximum = activities.Count;
            }
            foreach (IActivity otherActivity in activities)
            {
                //double MinDistStretch = Settings.Radius*2*2;
                //totDist, totTime, totDistRef, totTimeRef, noStretches
                PointInfo[] res;

                if (points.ContainsKey(otherActivity))
                {
                    IItemTrackSelectionInfo[] i = getSelInfo(new DateTime[] { otherActivity.StartTime, otherActivity.StartTime },
                        points[otherActivity], out res, useActive);

                    result.Add(otherActivity, res);
                }
                if (progressBar != null)
                {
                    progressBar.Increment(1);
                }
            }
            return result;
        }