コード例 #1
0
ファイル: Program.cs プロジェクト: Zaneo/WineExcel
        static void Main(string[] args)
        {
            try
            {
                Console.Title = "WineExcel";
            #if DEBUG
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
            #endif
                RawReader.ReadProducts("productMapping.txt");
                RawReader.ReadFile("data.dat");
                _storeProducts = RawReader.GetStoreProductEntries();
                _products = RawReader.GetProducts();
                RawReader.ResetStoreProductPairs();

                using (_eIo = new ExcelIO()) {
                    _eIo.OpenProducers();
                    _producers = _eIo.ReadProducers();
                }
                using (_eIo = new ExcelIO()) {
                    _eIo.OpenTemplate();
                    _eIo.SetupDocument(_products);
                    _eIo.WriteProductDataToStores(_storeProducts,_products, _producers);
                    _eIo.CleanupAndSaveCopy();
                }

            }
            catch (Exception e) {
                Console.WriteLine("An error occurred somewhere, a log will be written to 'ERROR" + DateTime.UtcNow.ToFileTimeUtc() + ".txt'. Please infom the developer");
                try {
                    File.WriteAllText("ERROR-" + DateTime.UtcNow.ToFileTimeUtc() + ".txt", e.Message+"\n" + e.StackTrace);
                }
                catch (Exception e2) {
                    Console.WriteLine("Writing the error log failed: " + e2.Message + "\nOriginal: " + e.Message + "\n" + e.StackTrace);
            #if DEBUG
                    throw e2;
            #endif
                }
            #if DEBUG
                throw e;
            #endif
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                Console.Title = "WineExcel";
#if DEBUG
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
#endif
                RawReader.ReadProducts("productMapping.txt");
                RawReader.ReadFile("data.dat");
                _storeProducts = RawReader.GetStoreProductEntries();
                _products      = RawReader.GetProducts();
                RawReader.ResetStoreProductPairs();

                using (_eIo = new ExcelIO()) {
                    _eIo.OpenProducers();
                    _producers = _eIo.ReadProducers();
                }
                using (_eIo = new ExcelIO()) {
                    _eIo.OpenTemplate();
                    _eIo.SetupDocument(_products);
                    _eIo.WriteProductDataToStores(_storeProducts, _products, _producers);
                    _eIo.CleanupAndSaveCopy();
                }
            }
            catch (Exception e) {
                Console.WriteLine("An error occurred somewhere, a log will be written to 'ERROR" + DateTime.UtcNow.ToFileTimeUtc() + ".txt'. Please inform the developer");
                try {
                    File.WriteAllText("ERROR-" + DateTime.UtcNow.ToFileTimeUtc() + ".txt", e.Message + "\n" + e.StackTrace);
                }
                catch (Exception e2) {
                    Console.WriteLine("Writing the error log failed: " + e2.Message + "\nOriginal: " + e.Message + "\n" + e.StackTrace);
#if DEBUG
                    throw e2;
#endif
                }
#if DEBUG
                throw e;
#endif
            }
        }
コード例 #3
0
        public void WriteProductDataToStores(Dictionary <int, Dictionary <int, ProductEntry> > sPp, Dictionary <int, Product> products, Producers pList)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("excel", "Either the excel app has been closed, or it was never opened");
            }
#if DEBUG
            Console.WriteLine("Getting Store Data From Template");
#endif
            _rObj = _worksheet[0].Range[StartingCellTemplate, Missing.Value];
            _rObj = _rObj.End[XlDirection.xlDown];
            string downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj            = _worksheet[0].Range[StartingCellTemplate, downAddress];
            object[,] values = (object[, ])_rObj.Value2;
#if DEBUG
            Console.WriteLine("Writing ProductInformation to Stores");
#endif
            int q;
            int lineList   = 1;
            int lineDeList = 1;
            for (int i = 1; i <= values.GetLength(0); i++)
            {
                int key = Convert.ToInt32(values[i, 1]);
                if (!sPp.ContainsKey(key))
                {
                    continue;
                }
                bool listed = sPp[key].Any(entry => entry.Value.ListingState == ListingStatus.Listed || entry.Value.ListingState == ListingStatus.Forced);
                q = 1;
                if (listed)
                {
                    foreach (var product in products)
                    {
                        if (sPp[key].ContainsKey(product.Key))
                        {
                            _worksheet[1].Cells[lineList + 1, StaticDataFieldCount + q] = sPp[key][product.Key].InventoryChange;
                            _worksheet[1].Cells[lineList + 1, StaticDataFieldCount + q].Interior.Color =
                                pList.GetProducerColourCodeFromProduct(product.Key);
                        }
                        q++;
                    }
                }
                _rObj = _worksheet[0].Range["A" + (i + 1), GetExcelColumnName(StaticDataFieldCount) + (i + 1)];
                if (listed)
                {
                    _rObj.Copy(_worksheet[1].Range["A" + (lineList + 1), GetExcelColumnName(StaticDataFieldCount) + (lineList + 1)]);
                    _worksheet[1].Cells[lineList + 1, StaticDataFieldCount + products.Count + 1] = DateTime.Now.ToShortDateString();
                    if (StaticDataFieldCountExtended > 0)
                    {
                        _rObj =
                            _worksheet[0].Range[
                                GetExcelColumnName(StaticDataFieldCount + 1) + (lineList + 1),
                                GetExcelColumnName(ExtendedDataReadEnd) + (lineList + 1)];

                        _rObj.Copy(_worksheet[1].Range[
                                       GetExcelColumnName(StaticDataFieldCount + products.Count + 2) + (lineList + 1),
                                       GetExcelColumnName(ExtendedDataReadEnd + products.Count + 1) + (lineList + 1)]);
                    }

                    lineList++;
                }
                else
                {
                    _rObj.Copy(_worksheet[2].Range["A" + (lineDeList + 1), GetExcelColumnName(StaticDataFieldCount) + (lineDeList + 1)]);

                    _worksheet[2].Cells[lineDeList + 1, StaticDataFieldCount + 1] = DateTime.Now.ToShortDateString();
                    lineDeList++;
                }
            }
            _rObj = _worksheet[1].Cells[2, StaticDataFieldCount + products.Count + 1];
            string upaddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj       = _rObj.End[XlDirection.xlDown];
            downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj       = _worksheet[1].Range[upaddress, downAddress];
            _rObj.EntireColumn.NumberFormat = "m/d/yyyy";
            _rObj       = _worksheet[2].Cells[2, StaticDataFieldCount + 1];
            upaddress   = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj       = _rObj.End[XlDirection.xlDown];
            downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj       = _worksheet[2].Range[upaddress, downAddress];
            _rObj.EntireColumn.NumberFormat = "m/d/yyyy";
        }
コード例 #4
0
ファイル: ExcelIO.cs プロジェクト: Zaneo/WineExcel
        public void WriteProductDataToStores(Dictionary<int, Dictionary<int,ProductEntry>> sPp, Dictionary<int, Product> products , Producers pList)
        {
            if (_isDisposed)
                throw new ObjectDisposedException("excel", "Either the excel app has been closed, or it was never opened");
            #if DEBUG
            Console.WriteLine("Getting Store Data From Template");
            #endif
            _rObj = _worksheet[0].Range[StartingCellTemplate, Missing.Value];
            _rObj = _rObj.End[XlDirection.xlDown];
            string downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _worksheet[0].Range[StartingCellTemplate, downAddress];
            object[,] values = (object[,])_rObj.Value2;
            #if DEBUG
            Console.WriteLine("Writing ProductInformation to Stores");
            #endif
            int q;
            int lineList = 1;
            int lineDeList = 1;
            for (int i = 1; i <= values.GetLength(0); i++) {
                int key = Convert.ToInt32(values[i, 1]);
                if (!sPp.ContainsKey(key)) continue;
                bool listed = sPp[key].Any(entry => entry.Value.ListingState == ListingStatus.Listed || entry.Value.ListingState == ListingStatus.Forced);
                q = 1;
                if (listed) {
                    foreach (var product in products) {
                        if (sPp[key].ContainsKey(product.Key)) {
                                _worksheet[1].Cells[lineList + 1, StaticDataFieldCount + q] = sPp[key][product.Key].InventoryChange;
                            _worksheet[1].Cells[lineList + 1, StaticDataFieldCount + q].Interior.Color =
                                pList.GetProducerColourCodeFromProduct(product.Key);
                        }
                        q++;
                    }
                }
                _rObj = _worksheet[0].Range["A" + (i + 1), GetExcelColumnName(StaticDataFieldCount) + (i + 1)];
                if (listed) {
                    _rObj.Copy(_worksheet[1].Range["A" + (lineList + 1), GetExcelColumnName(StaticDataFieldCount) + (lineList + 1)]);
                    _worksheet[1].Cells[lineList + 1, StaticDataFieldCount + products.Count + 1] = DateTime.Now.ToShortDateString();
                    if (StaticDataFieldCountExtended > 0)
                    {
                        _rObj =
                            _worksheet[0].Range[
                                GetExcelColumnName(StaticDataFieldCount + 1) + (lineList + 1),
                                GetExcelColumnName(ExtendedDataReadEnd) + (lineList + 1)];

                        _rObj.Copy(_worksheet[1].Range[
                            GetExcelColumnName(StaticDataFieldCount + products.Count + 2) + (lineList + 1),
                            GetExcelColumnName(ExtendedDataReadEnd + products.Count + 1) + (lineList + 1)]);
                    }

                    lineList++;
                } else {
                    _rObj.Copy(_worksheet[2].Range["A" + (lineDeList + 1), GetExcelColumnName(StaticDataFieldCount) + (lineDeList + 1)]);

                    _worksheet[2].Cells[lineDeList + 1, StaticDataFieldCount + 1] = DateTime.Now.ToShortDateString();
                    lineDeList++;
                }
            }
            _rObj = _worksheet[1].Cells[2, StaticDataFieldCount + products.Count + 1];
            string upaddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _rObj.End[XlDirection.xlDown];
            downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _worksheet[1].Range[upaddress, downAddress];
            _rObj.EntireColumn.NumberFormat = "m/d/yyyy";
            _rObj = _worksheet[2].Cells[2, StaticDataFieldCount + 1];
            upaddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _rObj.End[XlDirection.xlDown];
            downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _worksheet[2].Range[upaddress, downAddress];
            _rObj.EntireColumn.NumberFormat = "m/d/yyyy";
        }
コード例 #5
0
ファイル: ExcelIO.cs プロジェクト: Zaneo/WineExcel
        public Producers ReadProducers()
        {
            Producers pd = new Producers();
            Producer dummy = null;

            #if DEBUG
            Console.WriteLine("Reading producers");
            #endif

            _rObj = _worksheet[0].Range[SearchCellProducers, Missing.Value];
            _rObj = _rObj.End[XlDirection.xlDown];
            string downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _worksheet[0].Range[StartingCellProducers, "A" + downAddress.Substring(1)];
            object[,] values = (object[,])_rObj.Value2;
            for (int i = 1; i <= values.GetLength(0); i++) {
                if ((string)values[i,1] != null) {
                    dummy = new Producer();
                    dummy.ParseFromString((string)values[i,1]);
                    pd.AddProducer(dummy);
                }
                Debug.Assert(dummy != null, "dummy != null");
                pd.AddProduct(dummy.ID, _worksheet[0].Cells[i + StartingRowOffsetProducers, 2].Value2);
            }

            #if DEBUG
            Console.WriteLine("Successfully added {0} producer{1} with {2} product{3}",pd.Count, pd.Count != 0 ? "s" : "", pd.ProductCount, pd.ProductCount != 0 ? "s" : "");
            #endif
            Marshal.ReleaseComObject(_rObj);
            _rObj = null;
            return pd;
        }