예제 #1
0
        static ConverterBase GetConverter(string msg)
        {
            ConverterBase converter = null;

            do
            {
                Console.Write(msg + " => ");
                var unit = Console.ReadLine();
                converter = ConverterFactory.GetInstance(unit);
            } while (converter == null);
            return(converter);
        }
예제 #2
0
        public void SetSource(ExportTable source)
        {
            Workbook  book  = new Workbook();
            Worksheet sheet = book.Worksheets[0];

            foreach (ExportField field in source.Columns)
            {
                Cell wcell = sheet.Cells[0, field.ColumnIndex];
                wcell.PutValue(field.DisplayText);
            }

            foreach (ExportRow row in source.Rows)
            {
                foreach (ExportField field in source.Columns)
                {
                    Cell       wcell = sheet.Cells[row.Index + 1, field.ColumnIndex];
                    ExportCell ecell = row.Cells[field.ColumnIndex];
                    string     value = ecell.Value;

                    IConverter converter = ConverterFactory.GetInstance(field.Converter);
                    value = converter.Convert(value);

                    IDataType dataType = DataTypeFactory.GetInstance(field.DataType);
                    dataType.SetValue(value);
                    if (!dataType.IsValidDataType)
                    {
                        wcell.PutValue(value, false);
                    }
                    else
                    {
                        switch (field.DataType.ToLower())
                        {
                        case "integer":
                            //wcell.PutValue(int.Parse(value));
                            wcell.PutValue(value, true);
                            break;

                        case "double":
                            //wcell.PutValue(double.Parse(value));
                            wcell.PutValue(value, true);
                            break;

                        case "datetime":
                            //int styleIndex = book.Styles.Add();
                            //Style style = book.Styles[styleIndex];
                            //style.Number = 14;
                            //style.Custom = "yyyy/MM/dd;@";
                            //wcell.Style.Copy(style);
                            DateTime dt = Convert.ToDateTime(dataType.GetTypeValue());
                            wcell.PutValue(dt.ToShortDateString(), false);
                            //wcell.PutValue(DateTime.Parse(value));
                            break;

                        case "object":
                            wcell.PutValue((object)value);
                            break;

                        default:
                            wcell.PutValue(value, false);
                            break;
                        }
                    }
                }
            }
            _book = book;
        }
예제 #3
0
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var               li            = (sender as RadioButton);
            AbstractSample    sampleCreater = new SampleFactory();
            AbstractConverter converter     = new ConverterFactory();
            // Strings used to display the results
            string        syntaxString, resultType, operationString;
            TypeConverter pConverter  = converter.GetInstance(li.Name);
            string        string1     = sampleCreater.TakeSample(li.Name);
            var           pointResult = pConverter.ConvertFromString(string1);

            syntaxString    = $" {li.Name} = {li.Name}pConverter1.ConvertFromString(string1);";
            resultType      = $"{li.Name}";
            operationString = $"Converting a String to a {li.Name}";
            ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            //    switch (li.Name)
            //    {
            //        //begin switch

            //        case "rb1":
            //        {
            //                // Converts a String to a Point using a PointConverter
            //                // Returns a Point.

            //            TypeConverter pConverter = ConverterFactory.GetInstance("Point");
            //            var string1 = "10,20";

            //            var pointResult = (Point) pConverter.ConvertFromString(string1);



            //            syntaxString = "pointResult = (Point)pConverter1.ConvertFromString(string1);";
            //            resultType = "Point";
            //            operationString = "Converting a String to a Point";
            //            ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }

            //        case "rb2":
            //        {
            //                // Converts a String to a Vector using a VectorConverter
            //                // Returns a Vector.

            //                TypeConverter pConverter = new VectorConverter();
            //            var string1 = "10,20";

            //            var vectorResult = (Vector) pConverter.ConvertFromString(string1);
            //            // vectorResult is equal to (10, 20)

            //            // Displaying Results
            //            syntaxString = "vectorResult = (Vector)vConverter.ConvertFromString(string1);";
            //            resultType = "Vector";
            //            operationString = "Converting a String into a Vector";
            //            ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }

            //        case "rb3":
            //        {
            //                // Converts a String to a Matrix using a MatrixConverter
            //                // Returns a Matrix.

            //            TypeConverter pConverter = new MatrixConverter();
            //            var string2 = "10,20,30,40,50,60";

            //            var matrixResult = (Matrix) pConverter.ConvertFromString(string2);
            //            // matrixResult is equal to (10, 20, 30, 40, 50, 60)

            //            // Displaying Results
            //            syntaxString = "matrixResult = (Vector)mConverter.ConvertFromString(string2);";
            //            resultType = "Matrix";
            //            operationString = "Converting a String into a Matrix";
            //            ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }

            //        case "rb4":
            //        {
            //            // Converts a String to a Point3D using a Point3DConverter
            //            // Returns a Point3D.

            //            var p3DConverter = new Point3DConverter();
            //            var string3 = "10,20,30";

            //            var point3DResult = (Point3D) p3DConverter.ConvertFromString(string3);
            //            // point3DResult is equal to (10, 20, 30)

            //            // Displaying Results
            //            syntaxString = "point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);";
            //            resultType = "Point3D";
            //            operationString = "Converting a String into a Point3D";
            //            ShowResults(point3DResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }

            //        case "rb5":
            //        {
            //            // Converts a String to a Vector3D using a Vector3DConverter
            //            // Returns a Vector3D.

            //            var v3DConverter = new Vector3DConverter();
            //            var string3 = "10,20,30";

            //            var vector3DResult = (Vector3D) v3DConverter.ConvertFromString(string3);
            //            // vector3DResult is equal to (10, 20, 30)

            //            // Displaying Results
            //            syntaxString = "vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);";
            //            resultType = "Vector3D";
            //            operationString = "Converting a String into a Vector3D";
            //            ShowResults(vector3DResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }

            //        case "rb6":
            //        {
            //            // Converts a String to a Size3D using a Size3DConverter
            //            // Returns a Size3D.

            //            var s3DConverter = new Size3DConverter();
            //            var string3 = "10,20,30";

            //            var size3DResult = (Size3D) s3DConverter.ConvertFromString(string3);
            //            // size3DResult is equal to (10, 20, 30)

            //            // Displaying Results
            //            syntaxString = "size3DResult = (Size3D)v3DConverter.ConvertFromString(string3);";
            //            resultType = "Size3D";
            //            operationString = "Converting a String into a Size3D";
            //            ShowResults(size3DResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }

            //        case "rb7":
            //        {
            //            // Converts a String to a Point4D using a Point4DConverter
            //            // Returns a Point4D.

            //            var p4DConverter = new Point4DConverter();
            //            var string4 = "10,20,30,40";

            //            var point4DResult = (Point4D) p4DConverter.ConvertFromString(string4);
            //            // point4DResult is equal to (10, 20, 30)

            //            // Displaying Results
            //            syntaxString = "point4DResult = (Point4D)v3DConverter.ConvertFromString(string3);";
            //            resultType = "Point4D";
            //            operationString = "Converting a String into a Point4D";
            //            ShowResults(point4DResult.ToString(), syntaxString, resultType, operationString);
            //            break;
            //        }
            //    } //end switch
        }