コード例 #1
0
ファイル: GridInputTable.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// Looks for the column named "commentColumn" and applies to all columns from the list "addTags"
        /// the function AddColumnBetween. Displays the table obtained in such a way.
        /// An exception is thrown if any string from addTags and commentColumn is missing inside the first row.
        /// </summary>
        /// <param name="addTags"></param>
        public void DisplayAddTable(List <string> addTags, string commentColumn)
        {
            DateTime TimeOne     = DateTime.Now;
            MyTable  LocalTable  = TableInfo();///Put into the variable LocalTable the current content from the form.
            int      FoundColumn = LocalTable.FindInFirstRow(commentColumn);

            if (FoundColumn <= 0)
            {
                throw new ArgumentException("Wrong argument commentColumn passed to DisplayAddTable");
            }

            List <string> CommentColumn = LocalTable.GiveColumn(FoundColumn);

            for (int MyIterator = 1; MyIterator <= addTags.Count(); MyIterator++)
            {
                if (LocalTable.FindInFirstRow(addTags[MyIterator - 1]) <= 0)
                {
                    throw new ArgumentException("Wrong column name passed inside the argument addTags, the name is " + addTags[MyIterator - 1]);
                }
                LocalTable.AddColumnBetween(commentColumn, addTags[MyIterator - 1]);
            }
            DateTime     TimeTwo   = DateTime.Now;
            TimeSpan     MySpan    = (TimeTwo - TimeOne);
            const string AddedInfo = "GridInputTable|DisplayAddTable";

            MyStringOperations.LogInfo(MySpan, AddedInfo);
            DisplayTable(LocalTable);
        }
コード例 #2
0
ファイル: ArrayParser.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// Sets the variable "value" to the value corresponding to the next array member according to the rules of default culture and increases an Iterator variable by 1. If the value Values[Iterator-1] contains only spaces then "0" is put into the variable value.
        /// </summary>
        public void Set(ref int value)
        {
            if (Values[Iterator - 1].Trim().Length == 0)
            {
                value = 0;
            }
            else
            {
                if (MyStringOperations.IsValidInt(Values[Iterator - 1].Trim()) == false)
                {
                    Tuple <DialogResult, string> LocalAnswer =
                        Form1.GetValueStatic(String.Format("Wrong value has been passed to the function ArrayParser.Set the value is {0}, the first array element is {1}"
                                                           , value, Values[0]));


                    if (LocalAnswer.Item1 != DialogResult.OK)
                    {
                        Iterator++;
                        return;
                    }
                    else
                    {
                        value = Convert.ToInt32(Values[Iterator - 1]);
                    }
                }
                else
                {
                    value = Convert.ToInt32(Values[Iterator - 1]);
                }
            }


            Iterator++;
        }
コード例 #3
0
ファイル: GridInputTable.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// Collects the info from the control MyGridView2
        /// </summary>
        /// <returns></returns>
        public MyTable TableInfo()
        {
            DateTime DateOne = DateTime.Now;
            List <List <string> > MyContent  = new List <List <string> >();
            List <string>         HeaderList = new List <string>();

            //   MyGridView2.Columns.Count
            for (int Iterator = 1; Iterator <= MyGridView2.Columns.Count; Iterator++)
            {
                string MyHeader = MyGridView2.Columns[Iterator - 1].HeaderText;
                HeaderList.Add(MyHeader);
            }
            MyContent.Add(HeaderList);
            for (int Iterator = 1; Iterator <= MyGridView2.RowCount; Iterator++)
            {
                List <string> MyRowItem = new List <string>();
                for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.ColumnCount; ColumnIterator++)
                {
                    string CollectedValue = (MyGridView2[ColumnIterator - 1, Iterator - 1].Value is null) ?
                                            "" : MyGridView2[ColumnIterator - 1, Iterator - 1].Value.ToString();
                    MyRowItem.Add(CollectedValue);
                }
                MyContent.Add(MyRowItem);
            }
            DateTime DateTwo       = DateTime.Now;
            TimeSpan MySpan        = DateTwo - DateOne;
            MyTable  TableToReturn = new MyTable(MyContent);

            LogList.Add(MyStringOperations.LogInfo(MySpan));
            return(TableToReturn);
        }
コード例 #4
0
        /// <summary>
        /// "triplesXml" is the string of the type (Item)(Label)displayed label(/Label)(TypeToCollect)DateTime(/TypeToCollect)(DefaultValue)MyDefaultValue(/DefaultValue)
        /// (Key)MyKey(/Key)(/Item)...
        /// Returns a dictionary string in which MyKey is a key and value put by the user is a value
        /// </summary>
        /// <param name="triplesXml"></param>
        /// <returns></returns>
        public Tuple <DialogResult, Dictionary <string, string> > CollectData(string triplesXml)
        {
            List <string> SplittedItems = triplesXml.BetweenXmlItems();
            ///Below given list consists of: 1) labels, 2)default values, 3) strings which are put as keys' in the output
            List <Tuple <string, object, string> > ListToSend = new List <Tuple <string, object, string> > {
            };

            //FillData(List < Tuple<string, object, string> > myPairs)
            foreach (string MySplit in SplittedItems)
            {
                string LabelLocal         = MyStringOperations.BetweenTags(MySplit, MyTags.Label.ToString());
                string TypeToCollectLocal = MyStringOperations.BetweenTags(MySplit, MyTags.TypeToCollect.ToString());

                string DefaultValueLocal = MyStringOperations.BetweenTags(MySplit, MyTags.DefaultValue.ToString());
                string KeyLocal          = MyStringOperations.BetweenTags(MySplit, MyTags.Key.ToString());
                string ValueLocal        = MyStringOperations.BetweenTags(MySplit, MyTags.Key.ToString());

                if (TypeToCollectLocal.ToUpper().Equals(MyTypes.intType.ToString().ToUpper()))
                {
                    int MyValueInt = Convert.ToInt32(ValueLocal);
                    ListToSend.Add(new Tuple <string, object, string>(LabelLocal, MyValueInt, KeyLocal));
                }


                if (TypeToCollectLocal.ToUpper().Equals(MyTypes.DateTimeType.ToString().ToUpper()))
                {
                    int MyValueInt = Convert.ToInt32(ValueLocal);
                    ListToSend.Add(new Tuple <string, object, string>(LabelLocal, MyValueInt, KeyLocal));
                }
            }
            // MyFileOperation

            throw new NotImplementedException();
        }
コード例 #5
0
        /// <summary>
        /// Collects the data from the user.
        /// "myConstraints" is a dictionary with constraints which have to be satisfied by the enered data
        /// </summary>
        /// <param name="labels">labels which will be placed next to controls</param>
        /// <param name="values">default values which will be put inside controls</param>
        /// <param name="keys">keys which will be used inside the dictionary</param>
        /// <returns></returns>
        public Tuple <DialogResult, Dictionary <string, string> > FillData(ReadOnlyCollection <string> labels, List <object> values, List <string> keys, Dictionary <string, List <string> > myConstraints = null)
        {
            if (myConstraints != null)
            {
                AllowedValues = myConstraints;
            }

            if ((labels.Count() != values.Count()))
            {
                throw new ArgumentException("Provided lists should have the same length");
            }
            List <Tuple <string, object, string> > MyList = (from Number in Enumerable.Range(1, labels.Count())
                                                             select
                                                             new Tuple <string, object, string>(labels[Number - 1], values[Number - 1], keys[Number - 1])).ToList();
            Tuple <DialogResult, Dictionary <string, string> > MyOutcome = CollectData(MyList);



            string Serialized = "";

            foreach (string MyKey in MyOutcome.Item2.Keys)
            {
                string MyValue = MyOutcome.Item2[MyKey];
                Serialized += MyStringOperations.Xml(MyValue, MyKey);
            }

            ///  MyFileOperations.AppendFile(LogPath, Serialized);

            ////Now append the file situated at LogPath

            return(MyOutcome);
        }
コード例 #6
0
        /// <summary>
        /// If the control passed as an argument does not store a valid double then it is cleared
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyValidationDouble(object sender, CancelEventArgs e)
        {
            string MyValue = (sender as TextBox).Text;

            if (MyStringOperations.IsValidDouble(MyValue) == false)
            {
                MessageBox.Show("Wrong value");
                e.Cancel = true;
            }
            (sender as TextBox).BackColor = Color.Yellow;
        }
コード例 #7
0
        private void MyValidatingEvent(object sender, CancelEventArgs e)
        {
            string MyValue = (sender as TextBox).Text;

            if (MyStringOperations.IsValidInt(MyValue) == false)
            {
                (sender as TextBox).BackColor = Color.Red;
                e.Cancel = true;
            }
            else
            {
                (sender as TextBox).BackColor = Color.White;
            }
        }
コード例 #8
0
ファイル: GridInputTable.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// File|SaveFile
        /// Saves the content of the table stored in the control at the path selected by the user in the CSV
        /// format using a comma as a separator.
        /// </summary>
        private void SaveToCommaSeparatedClick(object sender, EventArgs e)
        {
            string DefaultDirectory = sender.ExtractTagInfo();

            if ((DefaultDirectory.Length > 0) && (System.IO.Directory.Exists(DefaultDirectory) == false))
            {
                throw new ArgumentException("There is no directory at the path " + DefaultDirectory);
            }

            MyTable ToCollect = TableInfo();///Puts into the variable ToCollect the content of the current instance

            ///Replace all semicolons
            for (int Iterator = 1; Iterator <= MyGridView2.RowCount; Iterator++)
            {
                for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.ColumnCount; ColumnIterator++)
                {
                    if (MyGridView2[ColumnIterator - 1, Iterator - 1].Value != null)
                    {
                        string Minu = MyGridView2[ColumnIterator - 1, Iterator - 1].Value.ToString();
                        if (MyStringOperations.AsciiSet1.Comma.Ist(Minu))
                        {
                            string ToReplace = MyStringOperations.C0Controls.ESC.ToString();
                            string ToPut     = MyStringOperations.Replace(Minu, MyStringOperations.AsciiSet1.Comma.ToString(), ToReplace);
                            MyGridView2[ColumnIterator - 1, Iterator - 1].Value           = ToPut;
                            MyGridView2[ColumnIterator - 1, Iterator - 1].Style.BackColor = Color.Red;
                        }
                    }
                }
            }
            SaveFileDialog MyDialog = new SaveFileDialog();

            if (DefaultDirectory.Length > 0)
            {
                MyDialog.InitialDirectory = DefaultDirectory;
            }
            DialogResult MyOutcome = MyDialog.ShowDialog();

            if (MyOutcome == DialogResult.OK)
            {
                ToCollect.SaveToCommaSeparated(MyDialog.FileName);
            }
            else
            {
                MessageBox.Show("Operation aborted");
            }

            CheckState();
        }
コード例 #9
0
        /// <summary>
        /// Checks if keys inside the property MyControls contain characters which are not within decimal Ascii range 32-126.
        /// The check is made only if the property IfCheck has the value true.
        /// </summary>
        private void CheckState()
        {
            DateTime TimeOne = DateTime.Now;

            if (IfCheck == false)
            {
                return;
            }
            foreach (string MojKlucz in MyControls.Keys)
            {
                if (MyStringOperations.ContainsUsualAscii(MojKlucz) == false)
                {
                    MessageBox.Show(String.Format("A key has been found with invalid characters - the string {0}", MojKlucz));
                }
            }
            DateTime TimeTwo = DateTime.Now;
            TimeSpan MySpan  = (TimeTwo - TimeOne);
        }
コード例 #10
0
ファイル: ArrayParser.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// Sets provided argument belonging to DateTime type.
        /// </summary>
        /// <param mainFile="value"></param>
        public void Set(ref DateTime value)
        {
            value = MyStringOperations.StringToDatesFormats(Values[Iterator - 1]);
            Iterator++;

            /*  switch (DateTimeFormat)
             * {*/
            /*  case DateTimeEnum.Normal:
             *    value =
             *        Convert.ToDateTime(Values[Iterator - 1]); break;*/
            /*   case DateTimeEnum.DottedDate:
             * (value=     MyStringOperations.StringToDatesFormats(Values[Iterator - 1])); break;*/
            /*  {
             *    try
             *    {
             *        ///The parsed input string  has the form 2012.07.24 03:10
             *        const int Unlimited = -1;
             *        const string Separator = " ";
             *        ///Splits the input string into "2012.07.24" and "03:10"
             *        string[] SplittedValues = Microsoft.VisualBasic.Strings.Split(Values[Iterator - 1], Separator, Unlimited, Microsoft.VisualBasic.CompareMethod.Binary);
             *        List<string> DateString = new List<string>();
             *        MyStringOperations.SplitDot(SplittedValues[0], ref DateString);
             *        List<string> HoursString = new List<string>();
             *        MyStringOperations.SplitColon(SplittedValues[1], ref HoursString);
             *        GeneralLibrary.MyCounter MC = new MyCounter();
             *        GeneralLibrary.MyCounter SC = new MyCounter();
             *
             *        value = MyStringOperations.ToDate(DateString[MC.Get() - 1], DateString[MC.Get() - 1], DateString[MC.Get() - 1], HoursString[SC.Get() - 1], HoursString[SC.Get() - 1], 0.ToString());
             *    }
             *    catch
             *    {
             *        value = Convert.ToDateTime(Values[Iterator - 1]); break;
             *    }
             * }*/

            /*    default: throw new ArgumentException("Profit could be calculated only for long and short instruments");
             * }
             *
             *
             * Iterator++;*/
        }
コード例 #11
0
ファイル: GridInputTable.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// Checks if the grid contains valid cells
        /// </summary>
        /// <returns></returns>
        public bool CheckState()
        {
            DateTime TimeOne = DateTime.Now;

            //  GeneralClass.
            for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.Columns.Count; ColumnIterator++)
            {
                for (int RowIterator = 1; RowIterator <= MyGridView2.RowCount; RowIterator++)
                {
                    string MyValue = MyGridView2[ColumnIterator - 1, RowIterator - 1].Value.ObjectToString();

                    if ((MyStringOperations.IsValidDouble(MyValue) == false) && (DoubleColumns.Contains(ColumnIterator)))

                    {
                        MessageBox.Show("Wrong value inside the column " + Convert.ToString(ColumnIterator) + ", the row " + Convert.ToString(RowIterator));
                    }
                }
            }
            DateTime TimeTwo = DateTime.Now;
            TimeSpan MySpan  = (TimeTwo - TimeOne);

            return(true);
        }
コード例 #12
0
        /// <summary>
        /// Replaces all strings having the form \label{name_of_label} with consecutive elements in Numbers, all
        /// strings of the form \ref{name_of_label} with numbers corresponding to the name_of_label
        /// Strings of the form "\label{name_of_label}" are added to the list
        /// Fills properties "LabelsFull" and "ReferencesFull"
        /// </summary>
        public void Replace()
        {
            const string AnyToFind = @"(.*?)";


            Regex LabelsRegex = new Regex(@"\\" + "label" + @"\{" + AnyToFind + @"\}");
            //Regex LabelsRegex = new Regex((MyStringOperations.ReplaceParameters(LabelsPattern, AnyToFind)));
            //Regex ReferenceRegex = new Regex(MyStringOperations.ReplaceParameters(ReferencePattern, AnyToFind));
            Regex ReferenceRegex = new Regex(Regex.Escape(@"\") + "ref" + Regex.Escape(@"{") + AnyToFind + Regex.Escape(@"}"));



            //Put into FoundLabels all labels found in the string Text
            MatchCollection FoundLabels = LabelsRegex.Matches(Text);


            const int StartNumber = 1;
            int       Number      = StartNumber;


            //Replace all labels with appropriate numbers
            foreach (Match Found in FoundLabels)
            {
                string LabelsString = MyStringOperations.ReplaceParameters(ReferencePattern, Found.Groups[1].ToString());

                Regex LabelsInstance = new Regex(LabelsString);


                string LabelFull = MyStringOperations.ReplaceParameters(LabelsPattern, Found.Groups[1].ToString());



                Text = LabelsInstance.Replace(Text, Number.ToString());
                Numbers.Add(Number);


                if (Labels.Contains(Found.Groups[1].ToString()))
                {
                    const string Duplicates = "Duplicate labels: ";
                    MessageBox.Show(Duplicates + Found.Groups[1].ToString());
                    //throw new InvalidOperationException(Duplicates + Found.Groups[1].ToString());
                }

                Labels.Add(Found.Groups[1].ToString());

                LabelsFull.Add(@Found.ToString());
                Number++;
            }


            MatchCollection FoundReferences = ReferenceRegex.Matches(Text);

            //Replace all references with appropriate numbers


            //Fill the properties: References and ReferencesFull
            foreach (Match Found in FoundReferences)
            {
                if (!References.Contains(Found.Groups[1].ToString()))
                {
                    References.Add(Found.Groups[1].ToString());
                    ReferencesFull.Add(@Found.ToString());
                }
            }


            foreach (string Reference in References)
            {
                if (!Labels.Contains(Reference))
                {
                    const string Unresolved = "Unresolved reference: ";
                    MessageBox.Show(Unresolved + Reference);
                    //throw new InvalidOperationException(Unresolved + Reference);
                }
                else
                {
                    int    ReferenceNumber = Labels.LastIndexOf(Reference) + 1;
                    string InstanceString  = MyStringOperations.ReplaceParameters(ReferencePattern, Reference);
                    Regex  Instance        = new Regex(InstanceString);
                    Text = Instance.Replace(Text, Numbers[ReferenceNumber - 1].ToString());
                }
            }
        }
コード例 #13
0
 /// <summary>
 /// Returns the reference corresponding to the label Word.
 /// </summary>
 /// <param mainFile="Word">A label.</param>
 /// <returns>The reference corresponding to the label Word.</returns>
 public static string GiveReference(string Word)
 {
     return(MyStringOperations.ReplaceParameters(ReferencePattern, Word) + MyStringOperations.Space);
 }
コード例 #14
0
ファイル: ArrayParser.cs プロジェクト: ardud/ClassLibrary
 /// <summary>
 /// Sets the variable "value" to the value corresponding to the next array member according to the rules of default culture and increases an Iterator variable by 1. If the value Values[Iterator-1] contains only spaces then "0.0" is put into the variable value.
 /// </summary>
 public void Set(ref double value)
 {
     value = (Values[Iterator - 1].Trim().Length > 0) ? MyStringOperations.ToDouble(Values[Iterator - 1]) : 0.0;
     Iterator++;
 }