Exemplo n.º 1
0
        public void Add(string msg, bool error = false)
        {
            if (!error && OnlyErrors)
            {
                return;
            }

            if (String.IsNullOrWhiteSpace(FilePath))
            {
                return;
            }

            try
            {
                // Процедура добавляет в конец файла новую строку сообщения
                // Попытаемся сделать запись, через попытку/исключение, очень часто политика безопастности запрещает пользователю записывать файл
                StreamWriter OutputFile;
                OutputFile = File.AppendText(FilePath);
                OutputFile.WriteLine(DateTime.Now.ToString() + " -- " + msg);
                OutputFile.Close();
            }
            catch (Exception)
            {
                //не удалось записать файл
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// saves the contents of the list box to a designated file location for future ref
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveEx_Click(object sender, EventArgs e)
        {
            //create output file streamwriter
            StreamWriter OutputFile;

            //try catch for debugging
            try
            {
                //detect whether or not a file has been opened
                if (CurrentFile != "")
                {
                    //Use teh current file to creat a text file using the output file object
                    OutputFile = File.CreateText(CurrentFile);
                    //create a loop to write each line of the lst box to the new file
                    for (int i = 0; i < lstBoxExLog.Items.Count; i++)
                    {
                        // write each item to the file
                        OutputFile.WriteLine(lstBoxExLog.Items[i]);
                    }

                    //close the output file
                    OutputFile.Close();
                }
                //allow the user to save a new file because one has not been selected to begin with.
                else
                {
                    //if else to make sure the user chooses a file path to save
                    if (saveFDToFile.ShowDialog() == DialogResult.OK)
                    {
                        //open the output file with createText
                        OutputFile = File.CreateText(saveFDToFile.FileName);

                        //reset the current file to user selected output file
                        CurrentFile = saveFDToFile.FileName;

                        //write a loop for the output file
                        for (int i = 0; i < lstBoxExLog.Items.Count; i++)
                        {
                            // write each item to the file
                            OutputFile.WriteLine(lstBoxExLog.Items[i]);
                        }

                        //close the file
                        OutputFile.Close();
                    }
                    else
                    {
                        //message box to show they cancelled the file opperation
                        MessageBox.Show("You canceled out of the save file operation, try again");
                    }
                }
            }
            catch (Exception ex)
            {
                //error message
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        //Finds all picture boxes and stores them into Seats List
        private void SaveAttendance_Click(object sender, EventArgs e)
        {
            Control[] matches;
            for (int i = 1; i <= 100; i++)
            {
                matches = this.Controls.Find("Seat" + i.ToString(), true);
                if (matches.Length > 0 && matches[0] is PictureBox)
                {
                    Seats.Add((PictureBox)matches[0]);
                }
            }


            //Accumulator for Total Absenses
            for (int i = 0; i < Seats.Count && i < StudentList.Count; i++)
            {
                if (Seats[i].BackColor == Color.Red)
                {
                    StudentList[i].Absenses += 1;
                }
            }

            //Writing ammended information back into CSV via SaveFileDialog
            SaveFileDialog SaveFile = new SaveFileDialog()
            {
                Filter = "CSV|*.csv"
            };

            try
            {
                if (SaveFile.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter OutputFile;
                    OutputFile = File.CreateText(SaveFile.FileName);

                    for (int i = 0; i < StudentList.Count; i++)
                    {
                        OutputFile.WriteLine(StudentList[i].FirstName + "," + StudentList[i].LastName + ","
                                             + StudentList[i].ZID + "," + StudentList[i].SeatNum + ","
                                             + StudentList[i].Absenses);
                    }

                    MessageBox.Show("File Saved Successfully!");
                    OutputFile.Close();
                }

                else
                {
                    MessageBox.Show("Something went wrong!");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
 public void Close()
 {
     try
     {
         Writer.Close();
         OutputFile.Close();
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            InputFile  input  = new InputFile("C-small-attempt1.in");
            OutputFile output = new OutputFile("output-small.txt");

            int[] values     = input.ReadIntArray();
            int   TEST_COUNT = values[0];

            for (int i = 0; i < TEST_COUNT; i++)
            {
                TestCase testCase = new TestCase(input);
                output.WriteCase(i + 1, testCase.GetSolution());
            }

            output.Close();
        }
        public void WriteCandles(XSymbol xs, int minutes, List <XCandle> candles)
        {
            string filename = string.Format("candles_{0}_{1}_{2}", xs.Exchange, xs.Symbol, GetBarPeriod(minutes * 60));
            var    fout     = new OutputFile <MarketCandle>(filename, Folder.crypto_folder, false);

            // Write candles to file
            foreach (var c in candles)
            {
                var propValues = Reflection.GetPropertyValues <XCandle>(c);
                var svalues    = propValues.Select(p => string.Format("{0}", p));
                var csv        = string.Join(",", svalues);
                //Console.WriteLine(csv);
                fout.WriteLine(csv);
            }
            fout.Close();
        }
Exemplo n.º 7
0
        //private void searchListbox_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //}

        private void confirmButton_Click_1(object sender, EventArgs e)      // Logic when the user clicks the confirm button
        {
            bool transactionValid = false, nameValid = false, phoneValid = false, emailValid = false;

            transactionValid = Regexp(@"^\d{6}$", transactionTextbox, transactionValid, transactionLbl, "Transaction No");          //Using Regular expression to make sure transaction no should have 6 digits
            nameValid        = Regexp(@"^[a-zA-Z\s]+$", clientTextbox, nameValid, clientLbl, "Client Name");                        //Using Regular expression to make sure client name value should include alphabets only
            phoneValid       = Regexp(@"^(353)(([ ][0-9]{3}){3})$", telephoneTextbox, phoneValid, telephoneLbl, "Phone Number");    //Using Regular expression to make sure Telephone no is of digits and in format (0353) XXXXX XXXXX
            emailValid       = Regexp(@"^([\w]+)@([\w]+)\.([\w]+)$", emailTextbox, emailValid, emailLbl, "Mail");                   //Using Regular expression to make sure email id displayed should have @ as well as a .

            if (transactionValid && nameValid && phoneValid && emailValid)
            {
                displayGroupbox.Visible = true;
                principalLabel.Text     = Principal.ToString("c", new CultureInfo("en-FR"));
                rateLabel.Text          = rate.ToString();
                termLabel.Text          = months.ToString();
                finalLabel.Text         = balanceValue.ToString("c", new CultureInfo("en-FR"));
                transactionLabel.Text   = transactionTextbox.Text;
                clientLabel.Text        = clientTextbox.Text;
                telephoneLabel.Text     = telephoneTextbox.Text;
                emailLabel.Text         = emailTextbox.Text;

                DialogResult result = MessageBox.Show("Are you sure you want to execute the transaction?", "Final Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    MessageBox.Show("Your transaction has been processed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    StreamWriter OutputFile;
                    OutputFile = File.AppendText("Transaction_Details.txt");                  // code to make sure, in case of sucessful trnsaction the records should be written on the text file
                    OutputFile.WriteLine("TRANSACTION NO:" + transactionLabel.Text + ";" + "PRINCIPAL AMOUNT:" + principalLabel.Text + ";" + "ACCRUED BALANCE:" + finalLabel.Text + ";" + "RATE:" + rateLabel.Text + ";" + "TERM:" + termLabel.Text + ";" + "CLIENT NAME:" + clientLabel.Text + ";" + "TELEPHONE NO:" + telephoneLabel.Text + ";" + "EMAIL ADDRESS:" + emailLabel.Text);
                    OutputFile.Close();
                    displayGroupbox.Visible     = false;
                    transactionGroupbox.Visible = false;

                    count = count + 1;
                    accrudedCompoundinterest = balanceValue - Principal;
                    totalPrincipalamount     = totalPrincipalamount + Principal;
                    sumCompoundinterest      = sumCompoundinterest + accrudedCompoundinterest;
                    sumBalancevalue          = sumBalancevalue + balanceValue;
                }
                else
                {
                    MessageBox.Show("Transaction has failed to execute. Please try again!");   // in case the user clicks No button meaning s/he doesnt wish to proceed with the transaction
                    displayGroupbox.Visible = false;
                }
            }
            summaryButton.Enabled = true;
            clearButton.Enabled   = true;
        }
Exemplo n.º 8
0
        public void RunModelForData(IModel model, Int32 totalTime)
        {
            Double[][] sData;
            if (model.isNetwork)
            {
                sData = this.RunModelForDataNetwork(model, totalTime);
            }
            else
            {
                sData = this.RunModelForDataNeuron(model, totalTime);
            }
            String     suffix = (this.neuronRegime == NeuronRegime.Bursting ? "bst" : "exc");
            OutputFile of     = new OutputFile(model.ToString() + "_" + suffix + ".dat");

            of.WriteData("0.00000000e+000", "\t", "#t\tV", true, sData);
            of.Close();
        }
Exemplo n.º 9
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             if (OutputFile != null)
             {
                 OutputFile.Close();
                 OutputFile.Dispose();
                 OutputFile = null;
             }
             if (InputFile != null)
             {
                 InputFile.Close();
                 InputFile.Dispose();
                 InputFile = null;
             }
         }
     }
     disposed = true;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Flushes out all query results content to the output file and puts the metadata store in read mode
        /// </summary>
        public void Commit()
        {
            if (OutputFile != null && !OutputFile.IsFinished)
            {
                SaveTitlesIndex();
                SavePrerequisitesIndex();
                SaveBundlesIndex();
                SaveKbArticleIndex();
                SaveProductClassificationIndex();
                SaveFilesIndex();
                SaveSupersededndex();
                SaveDriversIndex();

                // Come last, after all indexes have been updated
                WriteIndex();
                OutputFile.Finish();
                OutputFile.Close();
                OutputFile = null;

                InputFile = new ZipFile(FilePath);
            }
        }
        public void RunModel(IModel model, Int32 totalTime)//, Double Iext)
        {
            Int32 mTotalTime = (Int32)((Double)model.ts_per_ms * (Double)totalTime);

            Double[] tData = new Double[mTotalTime];
            Double[] xData = new Double[mTotalTime];

            Int32 t = 0;

            while (t < mTotalTime)
            {
                //model.TimeStep(Iext);
                model.TimeStep();
                tData[t] = (Double)t * model.dt;
                xData[t] = model.GetV();
                t++;
            }

            String     suffix = (this.neuronRegime == NeuronRegime.Bursting? "bst" : "exc");
            OutputFile of     = new OutputFile(model.ToString() + "_" + suffix + ".dat");

            of.WriteData("0.00000000e+000", "\t", "#t\tV", true, tData, xData);
            of.Close();
        }
Exemplo n.º 12
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();
            }
        }