Пример #1
0
        private void ClearButton_Click(object sender, EventArgs e)
        {
            // code which clears the selected value and changes visisbility of form.
            QuantityValuesTextBox.Focus();
            QuantityValuesTextBox.SelectAll();
            ButtonPanelOne.Visible    = true;
            CancelButton.Visible      = true;
            DataGridViewPanel.Visible = false;
            DataGridCart.ClearSelection();
            DataGridCart.Rows.Clear();
            TotalCostValueTextBox.Text = "0";
            FinalValue = 0;
            QuantityValuesTextBox.Clear();
            ExitButton.Focus();
            BeerNamesListBox.SelectedItems.Clear();
            BeerSubTypeListBox.SelectedItems.Clear();
            PriceForBeerListBox.SelectedItems.Clear();
            DataGridCart.Visible          = false;
            TotalCostValueTextBox.Visible = false;
            TotalcostLabel.Visible        = false;

            DataGridCart.ClearSelection();
            DataGridCart.Rows.Clear();
        }
Пример #2
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();
            }
        }