private PdfPTable ProductsTable()
        {
            PdfPTable table = FormatConfig.Table(9, new float[] { 0.5f, 1.3f, 2.5f, 0.7f, 1f, 1f, 1f, 1f, 1f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Mã SP"));
            table.AddCell(FormatConfig.TableCellHeader("Tên và qui cách"));
            table.AddCell(FormatConfig.TableCellHeader("Jampo"));
            table.AddCell(FormatConfig.TableCellHeader("ĐVT"));
            table.AddCell(FormatConfig.TableCellHeader("Đầu kì"));
            table.AddCell(FormatConfig.TableCellHeader("Nhập"));
            table.AddCell(FormatConfig.TableCellHeader("Xuất"));
            table.AddCell(FormatConfig.TableCellHeader("Cuối kì"));

            foreach (ProductsReport item in productsReports)
            {
                if (string.IsNullOrEmpty(item.Index))
                {
                    table.AddCell(FormatConfig.TableCellBoldBody(item.ProductName, PdfPCell.ALIGN_LEFT, 9));
                }
                else
                {
                    table.AddCell(FormatConfig.TableCellBody(item.Index, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.ProductCode, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.ProductName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Jampo, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.UnitName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.FirstNumber, PdfPCell.ALIGN_RIGHT));
                    table.AddCell(FormatConfig.TableCellBody(item.ImportNumber, PdfPCell.ALIGN_RIGHT));
                    table.AddCell(FormatConfig.TableCellBody(item.ExportNumber, PdfPCell.ALIGN_RIGHT));
                    table.AddCell(FormatConfig.TableCellBody(item.LastNumber, PdfPCell.ALIGN_RIGHT));
                }
            }
            return(table);
        }
Ejemplo n.º 2
0
        private PdfPTable CustomerDetailTable()
        {
            PdfPTable table = FormatConfig.Table(7, new float[] { 0.5f, 1.5f, 2f, 2f, 1.2f, 1.3f, 1.5f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Ngày"));
            table.AddCell(FormatConfig.TableCellHeader("Mặt hàng"));
            table.AddCell(FormatConfig.TableCellHeader("Quy cách"));
            table.AddCell(FormatConfig.TableCellHeader("Số lượng"));
            table.AddCell(FormatConfig.TableCellHeader("ĐVT"));
            table.AddCell(FormatConfig.TableCellHeader("Tổng giá"));

            foreach (CustomerReport item in customerReports)
            {
                if (string.IsNullOrEmpty(item.Index))
                {
                    table.AddCell(FormatConfig.TableCellBoldBody(item.Date, PdfPCell.ALIGN_LEFT, 7));
                }
                else
                {
                    table.AddCell(FormatConfig.TableCellBody(item.Index, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Date, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.ProductName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.AttrName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Number, PdfPCell.ALIGN_RIGHT));
                    table.AddCell(FormatConfig.TableCellBody(item.Unit, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Cost, PdfPCell.ALIGN_RIGHT));
                }
            }
            table.AddCell(FormatConfig.TableCellBoldBody("Tổng", PdfPCell.ALIGN_RIGHT, 6));
            table.AddCell(FormatConfig.TableCellBody(lbTotal.Text.Split(' ')[2], PdfPCell.ALIGN_RIGHT));
            return(table);
        }
Ejemplo n.º 3
0
        public Formatter(FormatConfig config)
        {
            mFormatConfig = config;
            if (mFormatConfig.mEndOfLineCommentDelimiter == null)
            {
                mFormatConfig.mEndOfLineCommentDelimiter = string.Empty;
            }
            if (mFormatConfig.mFullLineCommentDelimiterBase == null)
            {
                mFormatConfig.mFullLineCommentDelimiterBase = string.Empty;
            }
            if (mFormatConfig.mBoxLineCommentDelimiter == null)
            {
                mFormatConfig.mBoxLineCommentDelimiter = string.Empty;
            }

            if (mFormatConfig.mAddSpaceLongComment)
            {
                mFullLineCommentDelimiterPlus = mFormatConfig.mFullLineCommentDelimiterBase + " ";
            }
            else
            {
                mFullLineCommentDelimiterPlus = mFormatConfig.mFullLineCommentDelimiterBase;
            }

            Reset();

            // Prep the static parts of the hex dump buffer.
            mHexDumpBuffer = new char[73];
            for (int i = 0; i < mHexDumpBuffer.Length; i++)
            {
                mHexDumpBuffer[i] = ' ';
            }
            mHexDumpBuffer[6] = ':';
        }
        private void ExportFile()
        {
            Global.checkDirSaveFile();
            var doc = new Document(PageSize.A4, 20, 20, 10, 10);

            PdfWriter       docWriter = PdfWriter.GetInstance(doc, new FileStream(BHConstant.SAVE_IN_DIRECTORY + @"\Kho.pdf", FileMode.Create));
            PdfWriterEvents writerEvent;

            Image watermarkImage = Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory + @"logo.png");

            watermarkImage.SetAbsolutePosition(doc.PageSize.Width / 2 - 70, 600);
            writerEvent         = new PdfWriterEvents(watermarkImage);
            docWriter.PageEvent = writerEvent;

            doc.Open();

            doc.Add(FormatConfig.ParaRightBeforeHeader("In ngày : " + BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATETIME_FORMAT)));
            doc.Add(FormatConfig.ParaHeader("BÁO CÁO KHO VÀ THÀNH PHẨM"));

            doc.Add(FormatConfig.ParaRightBelowHeader("(" + textForPrint + ")"));
            if (modeReport != 1)
            {
                doc.Add(ProductsTable());
            }
            else
            {
                doc.Add(FormatConfig.ParaCommonInfo("Sản phẩm : ", textInfo));
                doc.Add(ProductDetailTable());
            }
            doc.Add(FormatConfig.ParaCommonInfo("Ghi chú : ", String.Concat(Enumerable.Repeat("...", 96))));

            doc.Close();
        }
Ejemplo n.º 5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            FormatConfig.RegisterFormats(GlobalConfiguration.Configuration.Formatters);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The application start method.
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            TraceConfig.RegisterListener(GlobalConfiguration.Configuration);
            FormatConfig.ConfigureFormats(GlobalConfiguration.Configuration);
            DependencyConfig.ResolveDependencies(GlobalConfiguration.Configuration);
            DocumentationConfig.Configure(GlobalConfiguration.Configuration);

            // Ensure that your Web API is only accessed via HTTPS
            // GlobalConfiguration.Configuration.Filters.Add(new MyEvents.Api.Authentication.OnlyHttpsAttribute());
        }
Ejemplo n.º 7
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            var cors = new EnableCorsAttribute("*", "*", "*");

            config.EnableCors(cors);
            // Web API routes
            config.MapHttpAttributeRoutes();
            FormatConfig.Formatters(config);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Ejemplo n.º 8
0
        private void ExportFile()
        {
            Global.checkDirSaveFile();
            var             doc       = new Document(PageSize.A4, 20, 20, 10, 10);
            PdfWriter       docWriter = PdfWriter.GetInstance(doc, new FileStream(BHConstant.SAVE_IN_DIRECTORY + @"\KHang.pdf", FileMode.Create));
            PdfWriterEvents writerEvent;

            Image watermarkImage = Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory + @"logo.png");

            watermarkImage.SetAbsolutePosition(doc.PageSize.Width / 2 - 70, 550);
            writerEvent         = new PdfWriterEvents(watermarkImage);
            docWriter.PageEvent = writerEvent;

            doc.Open();

            doc.Add(FormatConfig.ParaRightBeforeHeader("In ngày : " + BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATETIME_FORMAT)));
            doc.Add(FormatConfig.ParaHeader("DANH SÁCH KHÁCH HÀNG"));

            PdfPTable table = FormatConfig.Table(7, new float[] { 0.5f, 2f, 1.3f, 1.3f, 2f, 1.6f, 1.3f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Tên khách hàng"));
            table.AddCell(FormatConfig.TableCellHeader("Mã KH"));
            table.AddCell(FormatConfig.TableCellHeader("SĐT Cty"));
            table.AddCell(FormatConfig.TableCellHeader("Địa chỉ"));
            table.AddCell(FormatConfig.TableCellHeader("Người liên lạc"));
            table.AddCell(FormatConfig.TableCellHeader("SĐT"));

            for (int i = 0; i < customers.Count; i++)
            {
                table.AddCell(FormatConfig.TableCellBody((i + 1).ToString(), PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(customers[i].CustomerName, PdfPCell.ALIGN_LEFT));
                table.AddCell(FormatConfig.TableCellBody(customers[i].CustCode, PdfPCell.ALIGN_LEFT));
                table.AddCell(FormatConfig.TableCellBody(customers[i].Phone, PdfPCell.ALIGN_LEFT));
                table.AddCell(FormatConfig.TableCellBody(customers[i].Address, PdfPCell.ALIGN_LEFT));
                table.AddCell(FormatConfig.TableCellBody(customers[i].ContactPerson, PdfPCell.ALIGN_LEFT));
                table.AddCell(FormatConfig.TableCellBody(customers[i].ContactPersonPhone, PdfPCell.ALIGN_LEFT));
            }
            doc.Add(table);
            doc.Add(FormatConfig.ParaCommonInfo("Ghi chú : ", String.Concat(Enumerable.Repeat("...", 96))));

            doc.Close();
        }
Ejemplo n.º 9
0
        private void ExportFile()
        {
            Global.checkDirSaveFile();
            var             doc       = new Document(PageSize.A4, 20, 20, 10, 10);
            PdfWriter       docWriter = PdfWriter.GetInstance(doc, new FileStream(BHConstant.SAVE_IN_DIRECTORY + @"\CongNo.pdf", FileMode.Create));
            PdfWriterEvents writerEvent;

            Image watermarkImage = Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory + @"logo.png");

            watermarkImage.SetAbsolutePosition(doc.PageSize.Width / 2 - 70, 500);
            writerEvent         = new PdfWriterEvents(watermarkImage);
            docWriter.PageEvent = writerEvent;

            doc.Open();
            if (modeReport == 1)
            {
                doc.Add(FormatConfig.ParaRightBeforeHeaderRight(BHConstant.COMPANY_NAME));
                doc.Add(FormatConfig.ParaRightBeforeHeaderRight(BHConstant.COMPANY_ADDRESS));
                doc.Add(FormatConfig.ParaRightBeforeHeaderRight("ĐT: " + BHConstant.COMPANY_PHONE + " Fax: " + BHConstant.COMPANY_FAX));
            }

            doc.Add(FormatConfig.ParaRightBeforeHeader("In ngày : " + BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATETIME_FORMAT)));
            doc.Add(FormatConfig.ParaHeader("BÁO CÁO CÔNG NỢ"));

            doc.Add(FormatConfig.ParaRightBelowHeader("(" + textForPrint + ")"));
            if (modeReport != 1)
            {
                doc.Add(CustomersTable());
            }
            else
            {
                doc.Add(FormatConfig.ParaCommonInfo("Kính gửi : ", customerPrint.CustomerName));
                doc.Add(FormatConfig.ParaCommonInfo("Địa chỉ : ", customerPrint.Address));
                doc.Add(FormatConfig.ParaCommonInfo("ĐT : ", customerPrint.Phone + " Fax: " + customerPrint.Fax));
                doc.Add(CustomerDetailTable());
            }
            doc.Add(FormatConfig.ParaCommonInfo("", "Quý khách hàng kiểm tra và đối chiếu, nếu có thắc mắc vui lòng liên hệ số điện thoại trên."));
            doc.Add(FormatConfig.ParaCommonInfo("", "Chân thành cảm ơn sự hợp tác của quí khách."));
            doc.Add(FormatConfig.ParaCommonInfo("Ghi chú : ", String.Concat(Enumerable.Repeat("...", 96))));

            doc.Close();
        }
        private PdfPTable ProductDetailTable()
        {
            PdfPTable table = FormatConfig.Table(4, new float[] { 1f, 2.5f, 3.5f, 3f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Ngày"));
            table.AddCell(FormatConfig.TableCellHeader("Mã phiếu"));
            table.AddCell(FormatConfig.TableCellHeader("Số lượng"));

            int index = 0;

            foreach (ProductReport item in productReports)
            {
                table.AddCell(FormatConfig.TableCellBody((++index).ToString(), PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.UpdatedDateString, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.RecordCode, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.Amount, PdfPCell.ALIGN_RIGHT));
            }
            return(table);
        }
Ejemplo n.º 11
0
        private PdfPTable EmployeesTable()
        {
            PdfPTable table = FormatConfig.Table(5, new float[] { 1f, 2f, 2.5f, 2.5f, 2f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Ngày"));
            table.AddCell(FormatConfig.TableCellHeader("Nhân viên"));
            table.AddCell(FormatConfig.TableCellHeader("Mã phiếu"));
            table.AddCell(FormatConfig.TableCellHeader("Số tiền"));

            foreach (EmployeesReport item in employees_reports)
            {
                table.AddCell(FormatConfig.TableCellBody(item.Index.ToString(), PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.CreatedDate, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.EmployeeName, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.RecordCode, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.Amount, PdfPCell.ALIGN_RIGHT));
            }
            return(table);
        }
Ejemplo n.º 12
0
        private PdfPTable CustomersTable()
        {
            PdfPTable table = FormatConfig.Table(6, new float[] { 0.5f, 1.5f, 2.5f, 2.5f, 2f, 1f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Ngày"));
            table.AddCell(FormatConfig.TableCellHeader("Tên khách hàng"));
            table.AddCell(FormatConfig.TableCellHeader("Mã khách hàng"));
            table.AddCell(FormatConfig.TableCellHeader("Mã phiếu"));
            table.AddCell(FormatConfig.TableCellHeader("Số tiền"));

            foreach (CustomersReport item in customersReports)
            {
                table.AddCell(FormatConfig.TableCellBody(item.Index.ToString(), PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.Date, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.CustomerName, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.CustomerCode, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.RecordCode, PdfPCell.ALIGN_CENTER));
                table.AddCell(FormatConfig.TableCellBody(item.Amount, PdfPCell.ALIGN_RIGHT));
            }
            table.AddCell(FormatConfig.TableCellBoldBody("Tổng", PdfPCell.ALIGN_RIGHT, 5));
            table.AddCell(FormatConfig.TableCellBody(lbTotal.Text.Split(' ')[2], PdfPCell.ALIGN_RIGHT));
            return(table);
        }
Ejemplo n.º 13
0
        private PdfPTable EmployeeDetailTable()
        {
            PdfPTable table = FormatConfig.Table(9, new float[] { 0.5f, 1.3f, 1.5f, 1.3f, 1.4f, 1f, 1f, 1f, 1f });

            table.AddCell(FormatConfig.TableCellHeader("STT"));
            table.AddCell(FormatConfig.TableCellHeader("Ngày"));
            table.AddCell(FormatConfig.TableCellHeader("Tên khách hàng"));
            table.AddCell(FormatConfig.TableCellHeader("Mặt hàng"));
            table.AddCell(FormatConfig.TableCellHeader("Quy cách"));
            table.AddCell(FormatConfig.TableCellHeader("Số lượng"));
            table.AddCell(FormatConfig.TableCellHeader("ĐVT"));
            table.AddCell(FormatConfig.TableCellHeader("Đơn giá"));
            table.AddCell(FormatConfig.TableCellHeader("Hoa hồng"));

            foreach (EmployeeReport item in employee_reports)
            {
                if (string.IsNullOrEmpty(item.Index))
                {
                    table.AddCell(FormatConfig.TableCellBoldBody(item.CustomerName, PdfPCell.ALIGN_LEFT, 9));
                }
                else
                {
                    table.AddCell(FormatConfig.TableCellBody(item.Index, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Date, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.CustomerName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.ProductName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.AttrName, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Number, PdfPCell.ALIGN_RIGHT));
                    table.AddCell(FormatConfig.TableCellBody(item.Unit, PdfPCell.ALIGN_CENTER));
                    table.AddCell(FormatConfig.TableCellBody(item.Price, PdfPCell.ALIGN_RIGHT));
                    table.AddCell(FormatConfig.TableCellBody(item.Commission, PdfPCell.ALIGN_RIGHT));
                }
            }

            return(table);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Constructor.  Initializes various fields based on the configuration.  We want to
        /// do as much work as possible here.
        /// </summary>
        public Formatter(FormatConfig config)
        {
            mFormatConfig = config;     // copy struct
            if (mFormatConfig.mEndOfLineCommentDelimiter == null)
            {
                mFormatConfig.mEndOfLineCommentDelimiter = string.Empty;
            }
            if (mFormatConfig.mFullLineCommentDelimiterBase == null)
            {
                mFormatConfig.mFullLineCommentDelimiterBase = string.Empty;
            }
            if (mFormatConfig.mBoxLineCommentDelimiter == null)
            {
                mFormatConfig.mBoxLineCommentDelimiter = string.Empty;
            }

            if (string.IsNullOrEmpty(mFormatConfig.mNonUniqueLabelPrefix))
            {
                mFormatConfig.mNonUniqueLabelPrefix = "@";
            }

            if (mFormatConfig.mAddSpaceLongComment)
            {
                mFullLineCommentDelimiterPlus = mFormatConfig.mFullLineCommentDelimiterBase + " ";
            }
            else
            {
                mFullLineCommentDelimiterPlus = mFormatConfig.mFullLineCommentDelimiterBase;
            }

            // Prep the static parts of the hex dump buffer.
            mHexDumpBuffer = new char[73];
            for (int i = 0; i < mHexDumpBuffer.Length; i++)
            {
                mHexDumpBuffer[i] = ' ';
            }
            mHexDumpBuffer[6] = ':';

            // Resolve boolean flags to character or string values.
            if (mFormatConfig.mUpperHexDigits)
            {
                mHexFmtChar = 'X';
            }
            else
            {
                mHexFmtChar = 'x';
            }
            if (mFormatConfig.mSuppressHexNotation)
            {
                mHexPrefix = "";
            }
            else
            {
                mHexPrefix = "$";
            }
            if (mFormatConfig.mSuppressImpliedAcc)
            {
                mAccChar = "";
            }
            else if (mFormatConfig.mUpperOperandA)
            {
                mAccChar = "A";
            }
            else
            {
                mAccChar = "a";
            }
            if (mFormatConfig.mUpperOperandXY)
            {
                mXregChar = 'X';
                mYregChar = 'Y';
            }
            else
            {
                mXregChar = 'x';
                mYregChar = 'y';
            }
            if (mFormatConfig.mUpperOperandS)
            {
                mSregChar = 'S';
            }
            else
            {
                mSregChar = 's';
            }

            // process the delimiter patterns
            DelimiterSet chrDelim = mFormatConfig.mCharDelimiters;

            if (chrDelim == null)
            {
                Debug.WriteLine("NOTE: char delimiters not set");
                chrDelim = DelimiterSet.GetDefaultCharDelimiters();
            }

            switch (mFormatConfig.mHexDumpCharConvMode)
            {
            case FormatConfig.CharConvMode.Ascii:
                mHexDumpCharConv = CharEncoding.ConvertAscii;
                break;

            case FormatConfig.CharConvMode.LowHighAscii:
                mHexDumpCharConv = CharEncoding.ConvertLowAndHighAscii;
                break;

            case FormatConfig.CharConvMode.C64Petscii:
                mHexDumpCharConv = CharEncoding.ConvertC64Petscii;
                break;

            case FormatConfig.CharConvMode.C64ScreenCode:
                mHexDumpCharConv = CharEncoding.ConvertC64ScreenCode;
                break;

            default:
                // most some things don't configure the hex dump; this is fine
                mHexDumpCharConv = CharEncoding.ConvertLowAndHighAscii;
                break;
            }
        }
Ejemplo n.º 15
0
        private static string FormatDouble(string formatCode, double dv, out string color)
        {
            color = null;
            var trimmed = formatCode.Trim();

            if (trimmed.StartsWith("[") &&
                trimmed.Contains("]"))
            {
                var colorLen = trimmed.IndexOf(']');
                color = trimmed.Substring(1, colorLen - 1);
                if (ValidColors.Contains(color) ||
                    color.StartsWith("Color"))
                {
                    if (color.StartsWith("Color"))
                    {
                        var idxStr = color.Substring(5);
                        int colorIdx;
                        if (int.TryParse(idxStr, out colorIdx))
                        {
                            if (colorIdx < SmlDataRetriever.IndexedColors.Length)
                            {
                                color = SmlDataRetriever.IndexedColors[colorIdx];
                            }
                            else
                            {
                                color = null;
                            }
                        }
                    }
                    formatCode = trimmed.Substring(colorLen + 1);
                }
                else
                {
                    color = null;
                }
            }


            if (formatCode == "General")
            {
                return(dv.ToString(CultureInfo.InvariantCulture));
            }
            bool isDate = IsFormatCodeForDate(formatCode);
            var  cfc    = ConvertFormatCode(formatCode);

            if (isDate)
            {
                DateTime thisDate;
                try
                {
                    thisDate = DateTime.FromOADate(dv);
                }
                catch (ArgumentException)
                {
                    return(dv.ToString(CultureInfo.InvariantCulture));
                }
                if (cfc.StartsWith("[h]"))
                {
                    DateTime zeroHour     = new DateTime(1899, 12, 30, 0, 0, 0);
                    int      deltaInHours = (int)((thisDate - zeroHour).TotalHours);
                    var      newCfc       = cfc.Substring(3);
                    var      s            = (deltaInHours.ToString() + thisDate.ToString(newCfc)).Trim();
                    return(s);
                }
                if (cfc.EndsWith(".0"))
                {
                    var cfc2 = cfc.Replace(".0", ":fff");
                    var s4   = thisDate.ToString(cfc2).Trim();
                    return(s4);
                }
                var s2 = thisDate.ToString(cfc, CultureInfo.InvariantCulture).Trim();
                return(s2);
            }
            if (ExcelFormatCodeToNetFormatCodeExceptionMap.ContainsKey(formatCode))
            {
                FormatConfig fc = ExcelFormatCodeToNetFormatCodeExceptionMap[formatCode];
                var          s  = dv.ToString(fc.FormatCode, CultureInfo.InvariantCulture).Trim();
                return(s);
            }
            if ((cfc.Contains('(') && cfc.Contains(')')) || cfc.Contains('-'))
            {
                var s3 = (-dv).ToString(cfc, CultureInfo.InvariantCulture).Trim();
                return(s3);
            }
            else
            {
                var s4 = dv.ToString(cfc, CultureInfo.InvariantCulture).Trim();
                return(s4);
            }
        }