public List <XCandle> ReadCandles(string exchange, string symbol, int minutes)
        {
            var    result   = new List <XCandle>();
            string filename = string.Format("candles_{0}_{1}_{2}", exchange, symbol, GetBarPeriod(minutes * 60));
            var    fin      = new InputFile <XCandle>(filename, Folder.crypto_folder, false);
            string line;

            while ((line = fin.ReadLine()) != null)
            {
                var candle = new XCandle();
                Reflection.SetPropertyValues <XCandle>(candle, line);
                result.Add(candle);
                //Console.WriteLine(candle);
            }
            fin.Close();
            return(result);
        }
Example #2
0
        //
        // Method defiened for checking the uniqueness of each random number which is getting generated. This method is being used by another method GenerateUniqueTransnum
        private Boolean CheckUnique(string Transnum, string FileName)
        {
            Boolean      Unique = false;
            StreamReader InputFile;

            InputFile = File.OpenText(FileName);
            while (!InputFile.EndOfStream)
            {
                if (Transnum.Equals(InputFile.ReadLine()))
                {
                    InputFile.Close();
                    return(Unique);
                }
            }
            Unique = true;
            InputFile.Close();
            return(Unique);
        }
Example #3
0
        //
        // Method defiened for checking the uniqueness of each random number which is getting generated. This method is being used by another method GenerateUniqueTransnum
        private Boolean CheckUnique(string Transnum, string FileDirectory)
        {
            Boolean      Unique = false;
            StreamReader InputFile;

            string[] filePaths = Directory.GetFiles(FileDirectory);
            foreach (string filePath in filePaths)
            {
                InputFile = File.OpenText(filePath);
                while (!InputFile.EndOfStream)
                {
                    if (Transnum.Equals(InputFile.ReadLine()))
                    {
                        InputFile.Close();
                        return(Unique);
                    }
                }
                InputFile.Close();
            }
            Unique = true;
            return(Unique);
        }
Example #4
0
        //**************************************
        //
        // Import and Export Buttons
        //

        private void ImportRosterBttn_Click(object sender, EventArgs e)
        {
            try {
                StreamWriter DefaultRosterFile;

                DefaultRosterFile = File.CreateText("DefaultRosterFile.txt");

                DefaultRosterFile.WriteLine("Anderson, Pete");
                DefaultRosterFile.WriteLine("Coggins, Rich");
                DefaultRosterFile.WriteLine("McAndrew, Jim");
                DefaultRosterFile.WriteLine("Williams, Ted");

                DefaultRosterFile.Close();
                MessageBox.Show("Default roster file created. Click \"OK\" to import this roster.");
            } catch (Exception GenericException) {
                MessageBox.Show(GenericException.Message);
                return;
            }

            try {
                StreamReader InputFile;

                InputFile = File.OpenText("DefaultRosterFile.txt");
                AvailPlayersListBox.Items.Clear();

                while (!InputFile.EndOfStream)
                {
                    string PlayerNameString = InputFile.ReadLine();
                    AvailPlayersListBox.Items.Add(PlayerNameString);
                }

                InputFile.Close();
                MessageBox.Show("Default roster file imported. Click \"OK\" to continue.");
            } catch (Exception GenericException) {
                MessageBox.Show(GenericException.Message);
            }
        }
Example #5
0
        private void btnTotal_Click(object sender, EventArgs e)
        {
            ////////////// The code you sent me /////////////////////////////
            //try
            //{
            //    int number1, number2, number3, number4, number5, number6, number7, total;
            //    StreamReader inputFile;
            //    inputFile = File.OpenText("Sales.txt");

            //    number1 = int.Parse(inputFile.ReadLine());
            //    number2 = int.Parse(inputFile.ReadLine());
            //    number3 = int.Parse(inputFile.ReadLine());
            //    number4 = int.Parse(inputFile.ReadLine());
            //    number5 = int.Parse(inputFile.ReadLine());
            //    number6 = int.Parse(inputFile.ReadLine());
            //    number7 = int.Parse(inputFile.ReadLine());

            //    total = number1 + number2 + number3 + number4 + number5 + number6 + number7;

            //    MessageBox.Show("The total is " + total);

            //    inputFile.Close();
            //}
            //catch (Exception ex)
            //{

            //}

            ////////////// My code to do the same thing /////////////////////

            //---------------------------------------------------------------------------
            //1) Declare & create variables
            const int    SIZE = 20;
            StreamReader InputFile;              //to access text file

            decimal[] sales = new decimal[SIZE]; //decimal is best for money
            int       index = 0;
            decimal   temp;
            decimal   total = 0;

            //---------------------------------------------------------------------------
            //2) Open & read numeric strings from text file into array
            //      This file must be in folder TotalSales/TotalSales/bin/debug
            //      (The copy you had there was corrupted.)
            //      This must be done in a try block in case the file does not
            //          exist or does not open correctly or is in the wrong format, etc.
            try
            {
                InputFile = File.OpenText("sales.txt");         //open file

                index = 0;                                      //set index to first subscript
                while (!InputFile.EndOfStream && index < SIZE)  //loop until done
                {
                    temp = decimal.Parse(InputFile.ReadLine()); //get next num

                    sales[index] = temp;
                    index++;                                            //increment counter
                }

                InputFile.Close();  //close the file

                // Display array contents in list box on Form1
                foreach (decimal d in sales)
                {
                    salesListbox.Items.Add(d);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);        //display the message for the exception
            }                                       //that happened so that we used the catch

            //---------------------------------------------------------------------------
            // Determine wether to continue processing
            // Alternatively, this whole section could be included in the try
            // block above without the "IF".

            if (index == 0) //if index is zero, no items were successfully read
            {
                MessageBox.Show("No items read, either an error occurred or file is empty.");
            }
            else
            {
                //3) Find the total of the numbers in sales array
                total = 0;
                foreach (decimal d in sales)
                {
                    total += d;
                }

                //4) Display total on Form1
                txtTotal.Text = total.ToString();

                //5) Fin the average, minimum and maximum & display on Form1

                //6) Either:
                //      sort the array, see example in text
                //   OR
                //      copy the contents of sales into a List<decimal> salesList
                //      then call the sort ...  salesList.Sort();
                //      then copy the items in the list into the list box for output

                //7) Display the sorted list in the list box on Form1
            }
        }
Example #6
0
        // Daily Sales button creates daily sales report and stores in Text file.
        private void DailySalesReportButton_Click(object sender, EventArgs e)
        {
            //Local variable declaration.
            double TotalPriceValue = 0;
            string today           = GetDateTime.ToString("dd-MM-yy");

            int[,] SoldItemArray = new int[14, 5];
            //an object of straemreader is created.
            StreamReader InputFile;

            // code to Open the stockFile.
            InputFile = File.OpenText("StockFile.txt");
            //code which uses Loop to read from file and stores in array.
            for (int i = 0; i < 14; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    DefaultStock[i, j] = int.Parse(InputFile.ReadLine());
                }
            }
            InputFile.Close();
            //code to find out the daily sales of item and stored in SoldItem array.
            for (int i = 0; i < 14; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    SoldItemArray[i, j] = DefaultStock[i, j] - TempStockArray[i, j];
                }
            }

            // object of StreamWriter class is created to write to the file.
            StreamWriter OutputFile = File.CreateText(today + "DailyTranscationReport.txt");

            OutputFile.WriteLine("Beer Palace Sales Report -- Daily salses \nTime Stamp --- " + GetDateTime);
            OutputFile.Write("\t\t\t\t\t");
            for (int k = 0; k <= 4; k++)
            {
                if (k == 1)
                {
                    OutputFile.Write(BeerSizeArray[k] + "\t\t");
                }

                else if (k == 3)
                {
                    OutputFile.Write("\t" + BeerSizeArray[k] + "\t\t");
                }
                else
                {
                    OutputFile.Write(BeerSizeArray[k] + "\t");
                }
            }
            OutputFile.Write("\tSale Value");
            for (int x = 0; x < 14; x++)
            {
                double saleperitem = 0;
                OutputFile.WriteLine();
                if (x == 1 || x == 4 || x == 8 || x == 10)
                {
                    OutputFile.Write(BeerNameArray[x] + "\t\t");
                }
                else if (x == 2 || x == 5 || x == 0 || x == 7 || x == 11 || x == 13)
                {
                    OutputFile.Write(BeerNameArray[x] + "\t\t\t");
                }
                else if (x == 3 || x == 9)
                {
                    OutputFile.Write(BeerNameArray[x] + "\t");
                }
                else if (x == 6)
                {
                    OutputFile.Write(BeerNameArray[x] + "\t\t\t\t");
                }


                else
                {
                    OutputFile.Write(BeerNameArray[x] + "\t\t\t\t");
                }

                for (int y = 0; y <= 4; y++)
                {
                    OutputFile.Write("\t" + SoldItemArray[x, y].ToString() + "\t\t");
                    if (SoldItemArray[x, y] != 0)
                    {
                        TotalPriceValue += SoldItemArray[x, y] * PriceArray[x, y];
                    }
                    else
                    {
                        TotalPriceValue += 0;
                    }
                    saleperitem += SoldItemArray[x, y] * PriceArray[x, y];
                }
                OutputFile.Write("\t\t" + saleperitem);
            }
            OutputFile.WriteLine("\n" + "Total Sold Price :" + CURRENCY + TotalPriceValue);
            OutputFile.Close();
            MessageBox.Show("Sale Report generated for today", "Confirmation Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #7
0
        // Confirm button which send transaction details to text file.
        private void button2_Click(object sender, EventArgs e)
        {
            ClearButton.Visible  = true;
            CancelButton.Visible = false;
            // Code to shift the focus to ClearButton.
            ClearButton.Focus();
            // Code to create string builder and formatted into Text File.
            StringBuilder sb = new StringBuilder();
            //Local variable declaration section.
            int DataGridCartLength = DataGridCart.RowCount;

            for (int i = 0; i < DataGridCartLength; i++)
            {
                // code to format the string and appended from datagrid view.
                sb.AppendLine(DataGridCart[0, i].Value?.ToString() + " 0f " + DataGridCart[2, i].Value?.ToString() + " " + DataGridCart[1, i].Value?.ToString() + " " + DataGridCart[3, i].Value?.ToString());
            }
            //decision construct to write the transaction text file.
            if (MessageBox.Show(string.Format(sb.ToString() + "Total Transaction Cost is" + CURRENCY + FinalValue.ToString()), "Confirmation Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //code which instanciates streamwriter class.
                StreamWriter OutputFile;
                //code to append the string to file.
                OutputFile = File.AppendText("TransactionsFile.txt");
                OutputFile.Close();
                // Local Variable declaration restriceted to this decision construct.
                string Temp;
                int    RandomNumber      = 0;
                int    BeerConfirmIndex  = BeerNamesListBox.SelectedIndex;
                int    BeerSizeConfirmed = BeerSubTypeListBox.SelectedIndex;
                //Code which copy the contents of original array to destination array.
                Array.Copy(TempStockArray, StockArray, TempStockArray.Length);
                //StockArray[BeerConfirmIndex, BeerSizeConfirmed] = TempStockArray[BeerConfirmIndex, BeerSizeConfirmed];
                // calling random number generation method.
                RandomNumberGenerator(ref RandomNumber);
                StreamReader InputFile;
                InputFile = File.OpenText("TransactionsFile.txt");
                while (!InputFile.EndOfStream)
                {
                    Temp = InputFile.ReadLine();
                    // To check and generate unique random number.
                    if (Temp == RandomNumber.ToString())
                    {
                        RandomNumberGenerator(ref RandomNumber);
                    }
                }
                InputFile.Close();
                //Code which appends transaction details from gridview to text file.
                StreamWriter FileOpen;
                FileOpen = File.AppendText("TransactionsFile.txt");
                FileOpen.WriteLine(RandomNumber);
                FileOpen.WriteLine(GetDateTime.ToShortDateString());
                for (int i = 0; i < DataGridCart.Rows.Count; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        FileOpen.WriteLine(DataGridCart[j, i].Value?.ToString());
                    }
                }
                FileOpen.WriteLine("123");
                FileOpen.Close();
            }
            // Decision construct if selected cart items will not be purchased.
            else
            {
                // code to clear the gridview cells.
                DataGridCart.ClearSelection();
                DataGridCart.Rows.Clear();
                TotalCostValueTextBox.Clear();
                QuantityValuesTextBox.Clear();
                ClearButton.Focus();
            }
        }
Example #8
0
        //====================== START OF FORM EVENTS  =========================

        /*
         * Event Handler for Form Load Event
         * Dynamically adding Categories to the UI
         * Fetching Product Stock file and building UI components
         * Fetching textfiles and storing data into the lists
         */
        private void MainForm_Load(object sender, EventArgs e)
        {
            RealTimer.Start();
            //Making UI changes
            SearchPanel.Visible       = false;
            InventoryGroupBox.Visible = false;
            ChangeButtonBorder(1);

            StreamReader InputFile;
            string       FileLine;

            //Initializing Lists for Application Use
            CategoryList        = new List <string>();  //Category List
            ProductList         = new List <Product>(); //Main Stock Product List
            SaleProductIDs      = new List <Product>(); //Sold Stock Product List
            CurrentCartProducts = new List <string>();  //Current Cart List for Enable/Disable purpose
            ProductIDs          = new List <string>();  //Product ID's of all products in the Inventory

            //Initializing Maximum categories to 50
            ProductCategoryList[] NewCatList = new ProductCategoryList[50];

            //Reading Category File and fetching Categories
            InputFile = File.OpenText(CATEGORYDATABASEFILENAME);
            while (!InputFile.EndOfStream)
            {
                FileLine = InputFile.ReadLine();
                //Initialzing CategoryList
                CategoryList.Add(FileLine);
                //Initialzing ProductCategoryList UserControl
                NewCatList[1] = new ProductCategoryList
                {
                    CatName = FileLine
                };
                //Adding Categories to the CategoryFlowLayoutPanel to show various categories
                CategoryFlowLayoutPanel.Controls.Add(NewCatList[1]);
            }
            InputFile.Close();

            //if Categories found, fetching products according to categories
            if (CategoryList.Count > 0)
            {
                //Reading Product Stock file
                InputFile = File.OpenText(PRODUCTDATABASEFILENAME);
                while (!InputFile.EndOfStream)
                {
                    //Creating two Sets,
                    //one for Storing Original Stock
                    //One for storing Sold stock in application Run
                    Product p1 = new Product();
                    Product p2 = new Product();
                    for (int i = 0; i < RECORDLENGTH; i++)
                    {
                        FileLine = InputFile.ReadLine();
                        switch (i)
                        {
                        case 0:
                            p1.ProductID = FileLine;
                            p2.ProductID = FileLine;
                            ProductIDs.Add(p1.ProductID);
                            break;

                        case 1:
                            p1.ProductCategory = FileLine;
                            p2.ProductCategory = FileLine;
                            break;

                        case 2:
                            p1.ProductName = FileLine;
                            p2.ProductName = FileLine;
                            break;

                        case 3:
                            p1.ProductPrice = decimal.Parse(FileLine);
                            p2.ProductPrice = decimal.Parse(FileLine);
                            break;

                        case 4:
                            p1.ProductQuantity = int.Parse(FileLine);
                            p2.ProductQuantity = 0;
                            break;
                        }
                    }
                    //Adding products to two seperate lists
                    ProductList.Add(p1);
                    SaleProductIDs.Add(p2);
                }
                InputFile.Close();
                toolTip1.Show("Select Desired Category to view Products", SaleButton);
            }
            else
            {
                MessageBox.Show("No Categories found in the Inventory. Try adding Categories first", "No Categories to List", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }