Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Thursday, 24 April 2014

Windows Application close current window open another window.Another windows close event trigger shows parent window

  First Window code for button click
          SecondWindow rfisreport = new SecondWindow();
            rfisreport.Parent = this;
            this.Hide();
            rfisreport.Show();

Second Window Code

 public FirstWindow Parent;

 protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            if(Parent!=null)              
            {
                Parent.Show();
            }
        }

Wednesday, 23 April 2014

Windows App Error log

  public static class ErrorLog
    {

       static string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"); //@"c:\RFIDLOG\log.txt";

        public static void WriteError(string error)
        {
            try
            {
                //StreamWriter sw = File.AppendText("log.txt");
                //sw.WriteLine(DateTime.Now + Environment.NewLine);
                //sw.WriteLine(error + Environment.NewLine);
                //sw.WriteLine(Environment.NewLine);
                //sw.Close();

                if (!File.Exists(path))
                {
                    // Create a file to write to.
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.WriteLine(DateTime.Now + Environment.NewLine);
                        sw.WriteLine(error + Environment.NewLine);
                        sw.WriteLine("---------------------------------------");

                    }
                }
                else
                {
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine(DateTime.Now + Environment.NewLine);
                        sw.WriteLine(error + Environment.NewLine);
                        sw.WriteLine("---------------------------------------");

                    }
                }
            }
            catch (Exception)
            {
                //
            }
        }
    }