Exemple #1
0
        //修改属性

        /*private void mustate(string GID,string groupname,string sign)
         * {
         *  foreach (ListViewItem item in this.lv_group.Items)
         *  {
         *      if (item.Text == GID)
         *      {
         *          item.SubItems[1].Text = groupname;
         *          item.SubItems[4].Text = sign;
         *      }
         *  }
         * }
         * private void state(string UID,string username,string sign)
         * {
         *
         * }*/
        //关闭窗口
        private void list_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                string sendmsg = "logout#" + UID;
                Bw.Write(sendmsg);
                Bw.Flush();
                iswork = false;
                Br.Close();
                Bw.Close();
            }
            catch
            { }
            Application.Exit();
        }
Exemple #2
0
        //  Making a Method to Display in Main
        public void CustomersAccount()
        {
            StreamWriter Ac;

            try
            {
                Ac = File.AppendText("C:\\Users\\RON TAYLOR\\Desktop\\Computer Programing\\Customer_Account.txt");

                Console.WriteLine("please enter customers previous reading");
                previous_meter = int.Parse(Console.ReadLine());
                Console.WriteLine("please enter customers current reading");
                current_meter       = int.Parse(Console.ReadLine());
                current_consumption = current_meter - previous_meter;
                Console.ReadLine();
                Ac.WriteLine(previous_meter);
                Ac.WriteLine(current_meter);
                Ac.WriteLine(current_consumption);
                Ac.WriteLine("Previous meter :{0} Current meter: {1} Current consumption :{2}", previous_meter, current_meter, current_consumption);
                Ac.Close();
            }
            catch
            {
                Console.WriteLine(" file not writtten ");
            }
            Console.ReadLine();



            StreamReader Bw;


            Bw = File.OpenText("C:\\Users\\RON TAYLOR\\Desktop\\Computer Programing\\Customer_Account.txt");

            Accdisplay = Bw.ReadLine();
            while (Accdisplay != null)
            {
                Console.WriteLine(Accdisplay);
                Accdisplay = Bw.ReadLine();
            }

            Bw.Close();
        }
Exemple #3
0
 public void Close()
 {
     Br.Close();
     Bw.Close();
     Client.Close();
 }
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            startCalculatingLock = true;
            int iterationsLeft = mainWindow.UserDefinedLFSRIterations;

            if (calculatingStoppedAt > 0)
            {
                iterationsLeft = calculatingStoppedAt;
            }
            if (pauseCalculatingLock || stopCalculatingLock)
            {
                pauseCalculatingLock = false;
                stopCalculatingLock  = false;
            }
            string       startButtonContent = (string)e.Argument;
            int          bitListCount       = bitViewModel.Bits.Count;
            int          sum;
            bool         saveGeneratedValue = false;
            int          counter            = 0;
            StreamWriter tw = new StreamWriter(mainWindow.FileManagement.Files[0]);

            tw.Dispose();
            BinaryWriter Bw = new BinaryWriter(File.Open(mainWindow.FileManagement.Files[0], FileMode.OpenOrCreate));

            Bw.Dispose();
            if (startButtonContent.Equals("Resume"))
            {
                if (mainWindow.FileManagement.Extension.Equals(".txt"))
                {
                    tw = File.AppendText(mainWindow.FileManagement.Files[0]);
                }
                else
                {
                    Bw = new BinaryWriter(File.Open(mainWindow.FileManagement.Files[0], FileMode.Append));
                }
            }
            else
            {
                iterationsLeft = mainWindow.UserDefinedLFSRIterations;
                if (mainWindow.FileManagement.Extension.Equals(".txt"))
                {
                    tw = new StreamWriter(mainWindow.FileManagement.Files[0]);
                }
                else
                {
                    Bw = new BinaryWriter(File.Open(mainWindow.FileManagement.Files[0], FileMode.OpenOrCreate));
                }
                this.Dispatcher.Invoke(() => { userDefinedProgressBar.Maximum = iterationsLeft; });
            }
            int           progress   = iterationsLeft;
            StringBuilder byteToSave = new StringBuilder();

            while (!pauseCalculatingLock && !stopCalculatingLock && iterationsLeft > 0)
            {
                if (saveGeneratedValue == true && cyclesUntilSavingCheck.Equals(0))
                {
                    if (mainWindow.FileManagement.Extension.Equals(".bin"))
                    {
                        if (byteToSave.Length == 0)
                        {
                            this.Dispatcher.Invoke(() =>
                            {
                                Bw.Write(Convert.ToByte(byteToSave.ToString(), 2));
                            });
                            byteToSave.Clear();
                        }
                        else
                        {
                            byteToSave.Append(bitViewModel.Bits[bitListCount - 1].BitValue);
                        }
                    }
                    else
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            tw.Write(bitViewModel.Bits[bitListCount - 1].BitValue);
                        });
                    }
                    (sender as BackgroundWorker).ReportProgress(0);
                    iterationsLeft--;
                    saveGeneratedValue = false;
                }
                sum = 0;
                for (int i = 0; i < bitListCount; i++)
                {
                    if (bitViewModel.Bits[i].BitState.Equals("On") && bitViewModel.Bits[i].BitValue.Equals(1))
                    {
                        sum++;
                    }
                }
                sum = sum % 2;
                for (int i = bitListCount - 1; i > 0; i--)
                {
                    bitViewModel.Bits[i].BitValue = bitViewModel.Bits[i - 1].BitValue;
                }
                bitViewModel.Bits[0].BitValue = sum;
                if (cyclesUntilSavingCheck.Equals(0) && bitViewModel.Bits[bitListCount - 1].BitValue.Equals(0))
                {
                    cyclesUntilSavingCheck = mainWindow.NewCyclesAtZero;
                }
                if (cyclesUntilSavingCheck.Equals(0) && bitViewModel.Bits[bitListCount - 1].BitValue.Equals(1))
                {
                    cyclesUntilSavingCheck = mainWindow.NewCyclesAtOne;
                    counter++;
                    saveGeneratedValue = true;
                }
                cyclesUntilSavingCheck--;
            }
            if (iterationsLeft == 0)
            {
                this.Dispatcher.Invoke(() =>
                {
                    startButton.Content          = "Start";
                    startButton.IsEnabled        = true;
                    userDefinedProgressBar.Value = 0;
                });
            }
            else
            {
                calculatingStoppedAt = iterationsLeft;
            }
            tw.Close();
            Bw.Close();
            startCalculatingLock = false;
        }