Esempio n. 1
0
        private void buttonAnalyzeWorksheet_Click(object sender, EventArgs e)
        {
            try
            {
                _worksheet = _workbookController.GetWorksheet(comboBoxWorksheet.SelectedIndex);

                List <ColumnAnalysis> previousColumnAnalysis = _columnAnalysis;

                ProgressForm progressDlg = new ProgressForm(String.Format(Messages.TitleReadingWorksheet, comboBoxWorksheet.SelectedItem.ToString()), this);

                if (progressDlg.ShowDialog() != DialogResult.OK || previousColumnAnalysis == _columnAnalysis)
                {
                    return;
                }

                // draw the data about the read items
                _itemSettings = new List <CreateDictionaryItemControl>();
                panelDictionaryContents.Controls.Clear();

                int yPos = 0;

                foreach (ColumnAnalysis ca in _columnAnalysis)
                {
                    CreateDictionaryItemControl cdic = new CreateDictionaryItemControl(ca);
                    cdic.Location = new Point(cdic.Margin.Left, cdic.Margin.Top + yPos);

                    panelDictionaryContents.Controls.Add(cdic);
                    _itemSettings.Add(cdic);

                    yPos += cdic.Height;
                }

                groupBoxDictionaryContents.Visible = true;
                groupBoxCreateDictionary.Visible   = true;
                textBoxNamePrefix.Text             = CSPro.Names.CreateFromLabel(comboBoxWorksheet.SelectedItem.ToString());
                buttonCreateDictionary.Enabled     = true;
                _lastSaveFilename = null;
            }

            catch (Exception exception)
            {
                MessageBox.Show(String.Format(Messages.ExcelIOError, exception.Message));
            }
        }
Esempio n. 2
0
        private void buttonAnalyzeWorksheet_Click(object sender,EventArgs e)
        {
            try
            {
                _worksheet = _workbookController.GetWorksheet(comboBoxWorksheet.SelectedIndex);

                List<ColumnAnalysis> previousColumnAnalysis = _columnAnalysis;

                ProgressForm progressDlg = new ProgressForm(String.Format(Messages.TitleReadingWorksheet,comboBoxWorksheet.SelectedItem.ToString()),this);

                if( progressDlg.ShowDialog() != DialogResult.OK || previousColumnAnalysis == _columnAnalysis )
                    return;

                // draw the data about the read items
                _itemSettings = new List<CreateDictionaryItemControl>();
                panelDictionaryContents.Controls.Clear();

                int yPos = 0;

                foreach( ColumnAnalysis ca in _columnAnalysis )
                {
                    CreateDictionaryItemControl cdic = new CreateDictionaryItemControl(ca);
                    cdic.Location = new Point(cdic.Margin.Left,cdic.Margin.Top + yPos);

                    panelDictionaryContents.Controls.Add(cdic);
                    _itemSettings.Add(cdic);

                    yPos += cdic.Height;
                }

                groupBoxDictionaryContents.Visible = true;
                groupBoxCreateDictionary.Visible = true;
                textBoxNamePrefix.Text = CSPro.Names.CreateFromLabel(comboBoxWorksheet.SelectedItem.ToString());
                buttonCreateDictionary.Enabled = true;
                _lastSaveFilename = null;
            }

            catch( Exception exception )
            {
                MessageBox.Show(String.Format(Messages.ExcelIOError,exception.Message));
            }
        }
Esempio n. 3
0
        private void buttonCreateDictionary_Click(object sender, EventArgs e)
        {
            string namePrefix = textBoxNamePrefix.Text.ToUpper();

            if (!CSPro.Names.IsValid(namePrefix))
            {
                string suggestedNamePrefix = CSPro.Names.CreateFromLabel(namePrefix);

                if (MessageBox.Show(String.Format(Messages.InvalidNameSuggestOther, namePrefix, suggestedNamePrefix), this.Text, MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                namePrefix = suggestedNamePrefix;
            }

            HashSet <string> usedNames = new HashSet <string>();

            string dictionaryName = CSPro.Names.CreateFromLabel(namePrefix + "_DICT");
            string levelName      = CSPro.Names.CreateFromLabel(namePrefix + "_LEVEL");
            string recordName     = CSPro.Names.CreateFromLabel(namePrefix + "_REC");

            usedNames.Add(dictionaryName);
            usedNames.Add(levelName);
            usedNames.Add(recordName);

            List <CreateDictionaryItemControl.ItemSelections> ids   = new List <CreateDictionaryItemControl.ItemSelections>();
            List <CreateDictionaryItemControl.ItemSelections> items = new List <CreateDictionaryItemControl.ItemSelections>();

            CreateDictionaryItemControl cdicForMessages = null;

            try
            {
                foreach (CreateDictionaryItemControl cdic in _itemSettings)
                {
                    cdicForMessages = cdic;

                    CreateDictionaryItemControl.ItemSelections selections = cdic.Selections;

                    if (!selections.IncludeItem)
                    {
                        continue;
                    }

                    if (!CSPro.Names.IsValid(selections.Name))
                    {
                        throw new Exception(String.Format(Messages.InvalidName, selections.Name));
                    }

                    if (usedNames.Contains(selections.Name))
                    {
                        throw new Exception(String.Format(Messages.AlreadyUsedName, selections.Name));
                    }

                    usedNames.Add(selections.Name);

                    int length = 0;

                    if (selections.IsNumeric)
                    {
                        length = selections.BeforeDecLength;

                        if (selections.AfterDecLength > 0)
                        {
                            if (selections.IsId)
                            {
                                throw new Exception(Messages.InvalidIdNumericDecimal);
                            }

                            if (selections.AfterDecLength > CSPro.Defines.MaxLengthDecimal)
                            {
                                throw new Exception(String.Format(Messages.InvalidLengthNumericDecimal, CSPro.Defines.MaxLengthDecimal));
                            }

                            length += selections.AfterDecLength + (checkBoxDecChar.Checked ? 1 : 0);
                        }

                        if (length > CSPro.Defines.MaxLengthNumeric)
                        {
                            throw new Exception(String.Format(Messages.InvalidLengthNumeric, CSPro.Defines.MaxLengthNumeric));
                        }
                    }

                    else
                    {
                        length = selections.AlphaLength;

                        if (length > CSPro.Defines.MaxLengthAlpha)
                        {
                            throw new Exception(String.Format(Messages.InvalidLengthAlpha, CSPro.Defines.MaxLengthAlpha));
                        }
                    }

                    if (length == 0)
                    {
                        throw new Exception(Messages.InvalidLengthZero);
                    }

                    if (selections.IsId)
                    {
                        ids.Add(selections);
                    }

                    else
                    {
                        items.Add(selections);
                    }
                }

                cdicForMessages = null;

                if (ids.Count == 0)
                {
                    throw new Exception(Messages.InvalidNumberIds);
                }

                // save the dictionary
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title  = Messages.CSProSaveTitle;
                sfd.Filter = Messages.CSProFileFilter;

                if (_lastSaveFilename != null)
                {
                    sfd.InitialDirectory = Path.GetDirectoryName(_lastSaveFilename);
                    sfd.FileName         = Path.GetFileName(_lastSaveFilename);
                }

                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                CSPro.DataDictionary dictionary = new CSPro.DataDictionary();
                dictionary.DecimalCharDefault = checkBoxDecChar.Checked;
                dictionary.ZeroFillDefault    = checkBoxZeroFill.Checked;

                dictionary.Name  = dictionaryName;
                dictionary.Label = textBoxNamePrefix.Text + " Dictionary";

                CSPro.Level level = new CSPro.Level(dictionary, 0);
                dictionary.AddLevel(level);
                level.Name  = levelName;
                level.Label = textBoxNamePrefix.Text + " Level";

                CSPro.Record record = new CSPro.Record(level);
                level.AddRecord(record);
                record.Name  = recordName;
                record.Label = textBoxNamePrefix.Text + " Record";

                int startingPos = 1;

                foreach (CreateDictionaryItemControl.ItemSelections selections in ids)
                {
                    AddItem(level.IDs, selections, ref startingPos);
                }

                foreach (CreateDictionaryItemControl.ItemSelections selections in items)
                {
                    AddItem(record, selections, ref startingPos);
                }

                record.Length = startingPos;

                CSPro.DataDictionaryWriter.Save(dictionary, sfd.FileName);
                _lastSaveFilename = sfd.FileName;
            }

            catch (Exception exception)
            {
                if (cdicForMessages != null)
                {
                    MessageBox.Show(String.Format("{0}: {1}", cdicForMessages.ColumnText, exception.Message));
                }

                else
                {
                    MessageBox.Show(exception.Message);
                }

                return;
            }
        }
Esempio n. 4
0
        private void AddItem(CSPro.Record record,CreateDictionaryItemControl.ItemSelections selections,ref int startingPos)
        {
            CSPro.Item item = new CSPro.Item(record);
            record.AddItem(item);
            item.Name = CSPro.Names.CreateFromLabel(selections.Name);
            item.Label = selections.Name;

            int length = 0;

            item.Start = startingPos;
            item.Numeric = selections.IsNumeric;

            if( item.Numeric )
            {
                item.ZeroFill = checkBoxZeroFill.Checked;

                length = selections.BeforeDecLength;

                if( selections.AfterDecLength > 0 )
                {
                    item.DecChar = checkBoxDecChar.Checked;
                    item.Decimal = selections.AfterDecLength;
                    length += selections.AfterDecLength + ( checkBoxDecChar.Checked ? 1 : 0 );
                }

                if( selections.CreateValueSet )
                {
                    CSPro.ValueSet vs = new CSPro.ValueSet(item);
                    item.AddValueSet(vs);
                    vs.Name = CSPro.Names.CreateFromLabel(item.Name + "_VS1");
                    vs.Label = item.Label;

                    foreach( double doubleValue in selections.Values )
                    {
                        CSPro.Value value = new CSPro.Value();
                        vs.AddValue(value);
                        value.Label = String.Format("Value {0}",doubleValue.ToString());

                        CSPro.ValuePair vp = new CSPro.ValuePair();
                        vp.From = doubleValue.ToString();

                        value.AddValuePair(vp);
                    }
                }
            }

            else
                length = selections.AlphaLength;

            item.Length = length;

            startingPos += length;
        }