Exemplo n.º 1
0
        private void BtnExport_Click(object sender, RibbonControlEventArgs e)
        {
            ExcelHelper.ToggleExcelEvents(Globals.ThisAddIn.excelApplication, false);
            Cursor.Current = Cursors.WaitCursor;
            RibbonMenu ribbonMenu   = (RibbonMenu)dynamicMenuAdd;
            string     addMenuLabel = ribbonMenu.Label;

            InitializeVariables.InitializeDatabaseTables();
            if (backgroundWorker1.IsBusy != true)
            {
                alert = new ProgressBarForm();
                switch (addMenuLabel)
                {
                case "Fields":
                    alert.Text = "Validating and Exporting Fields Data";
                    break;

                case "Dropdowns":
                    alert.Text = "Exporting dropdown data";
                    break;

                case "Descriptions":
                    alert.Text = "Exporting translated descriptions";
                    break;

                case "Fields and Dropdowns":
                    alert.Text = "Validating Fields and Exporting Fields and Dropdowns data";
                    break;
                }
                alert.Show();
                backgroundWorker1.RunWorkerAsync();
            }
            Cursor.Current = Cursors.Default;
            ExcelHelper.ToggleExcelEvents(Globals.ThisAddIn.excelApplication, true);
        }
Exemplo n.º 2
0
        private void MatterResults_SelectedIndexChanged(object sender, EventArgs e)
        {
            Common.Models.Matters.Matter matter = (Common.Models.Matters.Matter)MatterResults.SelectedItem;
            Task task;

            ProgressBarForm.Show();

            Globals.ThisAddIn.ActiveMatter = matter;

            task = new Task(() =>
            {
                Common.Net.Response <List <Common.Models.Forms.Form> > resp;

                resp = CommManager.ListFormsForMatter(matter.Id.Value);

                if (Extensions.DynamicPropertyExists(resp.Package, "Error"))
                {
                    if (Globals.ThisAddIn.CanLog)
                    {
                        LogManager.GetCurrentClassLogger().Error("Error: " + resp.Error);
                    }
                    MessageBox.Show("Error: " + resp.Error, "Error");
                }
                else
                {
                    FormResults.Invoke(new MethodInvoker(delegate
                    {
                        FormResults.DataSource    = resp.Package;
                        FormResults.DisplayMember = "Title";
                        FormResults.ValueMember   = "Id";

                        ProgressBarForm.Hide();
                        FormResults.Enabled = true;
                        Select.Enabled      = true;
                    }));
                }
            });

            task.Start();
        }
Exemplo n.º 3
0
        public static void Calculate(IList<IActivity> activities, List<CalculatedFieldsRow> filter, bool testRun)
        {
            if ((activities != null) && (activities.Count > 0))
            {
                var progressBarForm = new ProgressBarForm();
                progressBarForm.Text = Resources.StringResources.ProgressFormTitle;

                progressBarForm.Show();

                object result;

                int actualActivity = 0;

                try
                {
                    SmoothingBackup();

                    foreach (IActivity activity in activities)
                    {
                        if (testRun)
                        {
                            progressBarForm.ProgressBarLabelText = "Testing calculation of fields for activity " + ++actualActivity +
                                                                   "/30";
                            progressBarForm.ProgressBarValue += 1000000 / 30;
                        }
                        else
                        {
                            progressBarForm.ProgressBarLabelText = "Calculating fields for activity " + ++actualActivity +
                                                                   "/" + activities.Count.ToString();
                            progressBarForm.ProgressBarValue += 1000000 / activities.Count;
                        }

                        virtualFields.Clear();

                        foreach (var virtualFieldsRow in GlobalSettings.virtualFieldsRows)
                        {
                            SmoothingSetTemporary(virtualFieldsRow);

                            if (virtualFieldsRow.Condition != "")
                            {
                                var conditionResult = Evaluate(virtualFieldsRow.Condition, activity, "", virtualFieldsRow);

                                if (conditionResult != null && conditionResult.ToString() == "True")
                                {
                                    result = Evaluate(
                                        virtualFieldsRow.CalculatedExpression,
                                        activity,
                                        virtualFieldsRow.Condition,
                                        virtualFieldsRow);

                                    if (result == "")
                                    {
                                        result = "NaN";
                                    }
                                }
                                else
                                {
                                    result = "NaN";
                                }
                            }
                            else
                            {
                                result = Evaluate(virtualFieldsRow.CalculatedExpression, activity, "", virtualFieldsRow);
                            }

                            //throw new Exception(result.ToString());

                            if (result != null)
                            {
                                virtualFields.Add(virtualFieldsRow.CustomField.ToUpper(), result);
                            }

                            SmoothingSetDefault();
                        }

                        ICustomDataFieldObjectType type =
                            CustomDataFieldDefinitions.StandardObjectType(typeof(IActivity));

                        foreach (ICustomDataFieldDefinition definition in CalculatedFields.GetLogBook().CustomDataFieldDefinitions)
                        {
                            if (progressBarForm.Cancelled || (testRun && actualActivity >= 30))
                            {
                                SmoothingSetDefault();
                                progressBarForm.Close();
                                break;
                            }

                            if ((filter != null && filter.Exists((o) => (o.CustomField == definition.Name))) || filter == null)
                            {
                                if (definition.ObjectType == type &&
                                    GlobalSettings.calculatedFieldsRows.Exists(
                                        (o) => (o.CustomField == definition.Name && o.Active == "Y")))
                                {
                                    var allCalculatedFieldsRow = GlobalSettings.calculatedFieldsRows.Where((o) => o.CustomField == definition.Name);

                                    foreach (var calculatedFieldsRow in allCalculatedFieldsRow)
                                    {
                                        SmoothingSetTemporary(calculatedFieldsRow);

                                        if (calculatedFieldsRow.Condition != "")
                                        {
                                            var conditionResult = Evaluate(calculatedFieldsRow.Condition, activity, "", calculatedFieldsRow);

                                            if (conditionResult != null && conditionResult.ToString() == "True")
                                            {
                                                result = Evaluate(
                                                    calculatedFieldsRow.CalculatedExpression,
                                                    activity,
                                                    calculatedFieldsRow.Condition,
                                                    calculatedFieldsRow);
                                            }
                                            else
                                            {
                                                result = null;
                                            }
                                        }
                                        else
                                        {
                                            result = Evaluate(
                                                calculatedFieldsRow.CalculatedExpression, activity, "", calculatedFieldsRow);
                                        }

                                        if (result != null && !testRun)
                                        {
                                            if (definition.DataType.Id ==
                                                CustomDataFieldDefinitions.StandardDataTypes.NumberDataTypeId)
                                            {
                                                activity.SetCustomDataValue(definition, Double.Parse(result.ToString()));
                                            }
                                            else if (definition.DataType.Id ==
                                                     CustomDataFieldDefinitions.StandardDataTypes.TextDataTypeId)
                                            {
                                                activity.SetCustomDataValue(definition, result.ToString());
                                            }
                                            else if (definition.DataType.Id ==
                                                     CustomDataFieldDefinitions.StandardDataTypes.TimeSpanDataTypeId)
                                            {
                                                double seconds = double.Parse(result.ToString());
                                                activity.SetCustomDataValue(
                                                    definition,
                                                    new TimeSpan(
                                                        (int)(seconds / 3600),
                                                        (int)((seconds % 3600) / 60),
                                                        (int)(seconds % 60)));
                                            }
                                        }

                                        SmoothingSetDefault();
                                    }
                                }
                            }

                            Application.DoEvents();
                        }

                        virtualFields.Clear();

                        if (progressBarForm.Cancelled || (testRun && actualActivity >= 30))
                        {
                            SmoothingSetDefault();
                            progressBarForm.Close();
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    SmoothingSetDefault();
                    progressBarForm.Close();

                    throw;
                }

                SmoothingSetDefault();
                progressBarForm.Close();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The main worker thread
        /// </summary>
        /// <param name="options">A CMyOptions object</param>
        public static void ThreadFunc(Object options)
        {
            CMyOptions opts = (CMyOptions) options;
            SuperFileFinderDriver ffd = new SuperFileFinderDriver();
            List<String> availableDrives = ffd.GetDrives( opts.fOptionLocalDrivesOnly );
            List<String> drives = new List<String>();
            DateTime start = DateTime.Now;

            if ( opts.aOptionDrives.Count > 0 )
            {
                String str;

                foreach ( String o in opts.aOptionDrives )
                {
                    str = o;

                    if ( o == "." )
                    {
                        str = ffd.GetCurrentDirectory();

                        if ( !str.EndsWith( "\\" ) )
                        {
                            str += "\\";
                        }
                    }

                    foreach ( String d in availableDrives )
                    {
                        if ( str.ToUpper().Contains( d.ToUpper() ) )
                        {
                            try
                            {
                                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo( str );

                                if ( di.Exists )
                                {
                                    drives.Add( str );
                                }
                            }
                            catch ( SecurityException se )
                            {
                                Console.Error.WriteLine( se.ToString() );
                            }

                            break;
                        }
                    }
                }
            }
            else
            {
                drives = availableDrives;
            }

            if ( drives.Count > 0 )
            {
                int folder_count = 0;

                if ( opts.fJustFilenames == false )
                {
                    Console.WriteLine( "Searching for filenames containing [{0}] on drive{1} {2}",
                                        String.Join( " | ", opts.myArgs.ToArray() ).ToUpper(),
                                        drives.Count > 1 ? "s" : "",
                                        String.Join( ",", drives.ToArray() ).ToUpper() );
                }

                pbf = new ProgressBarForm();
                pbf.Show( 1000 );
                pbs = new ProgressBarSink( pbf );

                foreach ( String driveLetter in drives )
                {
                    folder_count += ffd.GetFoldersCount( driveLetter, pbs );
                }

                pbf.SetMax( folder_count );
                pbf.SetValue( 0 );

                foreach ( String driveLetter in drives )
                {
                    ffd.FindFolders( driveLetter, opts.myArgs, opts.fJustFilenames, pbs );
                }

                pbf.Hide();
            }
            else
            {
                Console.Error.WriteLine( "ERROR: Specified drives or folders do not exist- {0}",
                                         String.Join( ", ", opts.aOptionDrives.ToArray() ).ToUpper() );
            }

            if ( opts.fJustFilenames == false )
            {
                DateTime end = DateTime.Now;
                TimeSpan diff = end - start;
                Console.WriteLine( "{0} files found\nExecution time: {1}", ffd.Count, diff );
            }
        }