Click here to Skip to main content
11,704,768 members (53,067 online)

Silverlight / WPF

 
QuestionOpening new WPF form in seperate thread. Pin
Hema Bairavan2-Feb-13 8:31
memberHema Bairavan2-Feb-13 8:31 
AnswerRe: Opening new WPF form in seperate thread. Pin
SledgeHammer012-Feb-13 10:28
memberSledgeHammer012-Feb-13 10:28 
GeneralRe: Opening new WPF form in seperate thread. Pin
Hema Bairavan3-Feb-13 2:57
memberHema Bairavan3-Feb-13 2:57 
GeneralRe: Opening new WPF form in seperate thread. Pin
SledgeHammer013-Feb-13 7:41
memberSledgeHammer013-Feb-13 7:41 
GeneralRe: Opening new WPF form in seperate thread. Pin
Jason Gleim1-Mar-13 8:00
memberJason Gleim1-Mar-13 8:00 
QuestionHow to user control view open in center of main parent window ? Pin
rahul ameta2-Feb-13 1:56
memberrahul ameta2-Feb-13 1:56 
Questionarrange elements inside wpf Pin
Remix Mixdox1-Feb-13 22:27
memberRemix Mixdox1-Feb-13 22:27 
AnswerRe: arrange elements inside wpf Pin
Abhinav S3-Feb-13 7:02
mvpAbhinav S3-Feb-13 7:02 
QuestionCustom Controls Pin
Sawyer19881-Feb-13 7:05
memberSawyer19881-Feb-13 7:05 
QuestionApplication Launcher Pin
Mycroft Holmes31-Jan-13 13:49
memberMycroft Holmes31-Jan-13 13:49 
AnswerRe: Application Launcher Pin
Abhinav S1-Feb-13 8:22
mvpAbhinav S1-Feb-13 8:22 
QuestionWPF controls refresh Pin
caradri31-Jan-13 1:50
membercaradri31-Jan-13 1:50 
AnswerRe: WPF controls refresh Pin
Pete O'Hanlon31-Jan-13 2:44
protectorPete O'Hanlon31-Jan-13 2:44 
GeneralRe: WPF controls refresh Pin
caradri31-Jan-13 10:20
membercaradri31-Jan-13 10:20 
Laugh | :laugh:
i really wondered!!!
here is the class that create the files:
class Farmonicior
  {
      private string sourcpath = string.Empty;
 
      public string SourcePath
      {
          get
          {
              if (sourcpath==string.Empty)
                  global::System.Windows.MessageBox.Show("The Source Cannot be Empty!!!");
              return sourcpath;
          }
          set {sourcpath = value;}
      }
 

      private string resultFolder = string.Empty;
      /// <summary>
      /// If this is empty, the source folder will be used
      /// </summary>
      public string ResultFolder
      {
          get
          {
              if ( resultFolder == string.Empty)
              {
                  FileInfo fi = new FileInfo(sourcpath); //use the source forder path
                  resultFolder = fi.DirectoryName;
              }
              return resultFolder;
          }
          set { resultFolder = value; }
 
      }
 
      /// <summary>
      /// Create the files with the customer conditions
      /// </summary>
      public void FilesWork()
      {
          string line = string.Empty;
          List<string> LinesList = new List<string>();
          try
          {
              StreamReader StrRdr = new StreamReader(SourcePath);
              while ((line = StrRdr.ReadLine()) != null )
              {
                  if (line.StartsWith("LN"))
                  {
                      LinesList.Add(line);
                  }
              }
              StrRdr.Close();
          }
          catch (Exception ErrExc)
          {
              System.Windows.MessageBox.Show(ErrExc.Message,"Read Source.");
          }
 
           Singleton.Instance.ProgressBarMAX = LinesList.Count;
 
          try
          {
              Singleton.Instance.ProgressBarVAL = 0;
              string year = DateTime.Today.ToString("yy"); //year format 13, not 2013
              foreach (string item in LinesList)
              {
 
                  string[] lineArr = item.Split('|');
                  string newfile = string.Format(@"{0}\{1}_{2}.txt", ResultFolder, lineArr[2], lineArr[3]);
                  Singleton.Instance.NewFilesPath.Add(newfile);
                  StreamWriter StrWtr = new StreamWriter(newfile, false);
                  StrWtr.WriteLine(string.Format("yy"));
                  StrWtr.WriteLine(string.Format("nn|tttttt"));
 
                  if (lineArr.Length == 8)
                  {
                      if (lineArr[7] != "")
                          StrWtr.WriteLine("qwertyui");
                      else
                          StrWtr.WriteLine("poiuytrewq");
                  }
                  else
                      StrWtr.WriteLine(string.Format("HR|{0}|{1}", lineArr[3], year));
 
                  StrWtr.WriteLine(string.Format("RTG|{0}|{1}", lineArr[5], lineArr[6]));
                  StrWtr.WriteLine("END");
                  StrWtr.Close();
                  Singleton.Instance.ProgressBarVAL++;
              }
          }
          catch (Exception ErrExc)
          {
              System.Windows.MessageBox.Show(ErrExc.Message,"Create Files.");
          }
      }
  }

Here the MainWindows.cs

 public partial class MainWindow : Window,INotifyPropertyChanged
    {
        Farmonicior hrm = new Farmonicior();//implemetn the interface here

        public MainWindow()
        {
            InitializeComponent();
 
        }
 
        private void button1_Click(object sender, RoutedEventArgs e)//SourceFileTxtBx
        {
            PrgrssBar1.Value = 0;
            // Create OpenFileDialog 
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            // Set filter for file extension and default file extension 
            dlg.DefaultExt = ".txt";
            dlg.Filter = "Text documents (.txt)|*.txt";
            // Display OpenFileDialog by calling ShowDialog method 
            Nullable<bool> result = dlg.ShowDialog();
            // Get the selected file name and display in a TextBox 
            if (result == true)
            {
                string filename = dlg.FileName;
                SourceFileTxtBx.Text = filename;
                hrm.SourcePath = filename;
                ResulFolderTxtBx.Text = hrm.ResultFolder;
            }
        }
 
        private void button2_Click(object sender, RoutedEventArgs e) //ResulFolderTxtBx 
        {
            string selectedFolder = string.Empty;
            FolderBrowserDialog selectFolderDialog = new FolderBrowserDialog();
            selectFolderDialog.ShowNewFolderButton = true;
            if (selectFolderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Singleton.Instance.NewFilesPath.Clear();
                FilesNamesTxtBx.Clear();
                Singleton.Instance.ProgressBarVAL = 0;
                
                selectedFolder = selectFolderDialog.SelectedPath;
                ResulFolderTxtBx.Text = selectedFolder;
                hrm.ResultFolder = selectedFolder;
            }
        }
 
        private void GoBttn_Click(object sender, RoutedEventArgs e)
        {
            PrgrssBar1.Maximum = Singleton.Instance.ProgressBarMAX;
            if (hrm.SourcePath == string.Empty)
                System.Windows.MessageBox.Show("Must Select a source file");
            else
            {
                //Thread td = new Thread(hrm.FilesWork);
                // hrm.FilesWork();

               foreach (string item in Singleton.Instance.NewFilesPath)
               {
                   FilesNamesTxtBx.AppendText(item + Environment.NewLine);
               }
               FilesWork();
                //td.Start();
                //progresBarTxtBx.Text = "DONE!";
            }
 
        }
        
        public void ProgressBarStep()//I call this function from the set of the singleton Maxvalue prop
        {
            PrgrssBar1.Value++;
        }
 
        internal void updateProgressbarMax()//(int max)// colled from the set of the singleton progressbarmax
        {
            PrgrssBar1.Maximum = Singleton.Instance.ProgressBarMAX;//max; 
            progresBarTxtBx.Text = "Total files: " + Singleton.Instance.ProgressBarMAX.ToString();  //a textbox somewhere
        }
 
}

here the singleton

public sealed class Singleton
{
    MainWindow MW = new MainWindow();
    static readonly Singleton _instance = new Singleton();
 
    public static Singleton Instance
    {
        get { return _instance; }
    }
 
    int progBarVal;// = Properties.Settings.Default.upLeftX;
    public int ProgressBarVAL
    {
        get { return progBarVal; }
        set
        {
            progBarVal = value;
            MW.ProgressBarStep();
        }
    }
 
    int progBarMax;// = Properties.Settings.Default.upLeftY;
    public int ProgressBarMAX
    {
        get { return progBarMax; }
        set
        {
            progBarMax = value;
            MW.updateProgressbarMax();
        }
    }
 

    List<string> newfilePath = new List<string>();
    public List<string> NewFilesPath
    {
        get { return newfilePath; }
        set
        {
            newfilePath = value;
 
        }
    }
 
    private Singleton()
    {
    }
}

this is. I hope i copy enough. be nice if you see coding horrors. thanks.
GeneralRe: WPF controls refresh Pin
Richard Deeming31-Jan-13 11:25
memberRichard Deeming31-Jan-13 11:25 
GeneralRe: WPF controls refresh Pin
caradri2-Feb-13 17:59
membercaradri2-Feb-13 17:59 
GeneralRe: WPF controls refresh Pin
caradri3-Feb-13 20:16
membercaradri3-Feb-13 20:16 
QuestionRoutedEvent vs AttachedEvent Pin
devvvy29-Jan-13 22:30
memberdevvvy29-Jan-13 22:30 
AnswerRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon29-Jan-13 22:51
protectorPete O'Hanlon29-Jan-13 22:51 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy29-Jan-13 23:02
memberdevvvy29-Jan-13 23:02 
GeneralRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon30-Jan-13 0:45
protectorPete O'Hanlon30-Jan-13 0:45 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy30-Jan-13 2:40
memberdevvvy30-Jan-13 2:40 
GeneralRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon30-Jan-13 2:44
protectorPete O'Hanlon30-Jan-13 2:44 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy30-Jan-13 3:08
memberdevvvy30-Jan-13 3:08 
QuestionWPF Tab Item Close Button Pin
Kevin Marois29-Jan-13 18:03
memberKevin Marois29-Jan-13 18:03 
AnswerRe: WPF Tab Item Close Button Pin
SledgeHammer0129-Jan-13 19:02
memberSledgeHammer0129-Jan-13 19:02 
GeneralRe: WPF Tab Item Close Button Pin
Kevin Marois2-Feb-13 15:33
memberKevin Marois2-Feb-13 15:33 
GeneralRe: WPF Tab Item Close Button Pin
SledgeHammer012-Feb-13 18:25
memberSledgeHammer012-Feb-13 18:25 
QuestionCustom Control Template for beginners Pin
jeffdavis870329-Jan-13 9:12
memberjeffdavis870329-Jan-13 9:12 
AnswerRe: Custom Control Template for beginners Pin
SledgeHammer0129-Jan-13 11:32
memberSledgeHammer0129-Jan-13 11:32 
GeneralRe: Custom Control Template for beginners Pin
jeffdavis870329-Jan-13 12:10
memberjeffdavis870329-Jan-13 12:10 
GeneralRe: Custom Control Template for beginners Pin
SledgeHammer0129-Jan-13 12:46
memberSledgeHammer0129-Jan-13 12:46 
GeneralTreeview Selection Pin
vijilvs11628-Jan-13 23:03
membervijilvs11628-Jan-13 23:03 
QuestionProblem With TreeViewItem Tooltip Pin
Kevin Marois26-Jan-13 15:39
memberKevin Marois26-Jan-13 15:39 
GeneralRe: Problem With TreeViewItem Tooltip Pin
Thomas Duwe29-Jan-13 1:46
memberThomas Duwe29-Jan-13 1:46 
QuestionHow to get a value from treeview. Pin
boryborawski26-Jan-13 12:06
memberboryborawski26-Jan-13 12:06 
QuestionConstant header and footer Pin
columbos1492725-Jan-13 23:11
membercolumbos1492725-Jan-13 23:11 
AnswerRe: Constant header and footer Pin
Richard MacCutchan26-Jan-13 0:05
mvpRichard MacCutchan26-Jan-13 0:05 
QuestionWPF.MDI Pin
columbos1492725-Jan-13 8:37
membercolumbos1492725-Jan-13 8:37 
AnswerRe: WPF.MDI Pin
Abhishek Pant25-Jan-13 9:29
memberAbhishek Pant25-Jan-13 9:29 
GeneralRe: WPF.MDI Pin
columbos1492725-Jan-13 22:11
membercolumbos1492725-Jan-13 22:11 
GeneralRe: WPF.MDI Pin
Abhishek Pant25-Jan-13 22:33
memberAbhishek Pant25-Jan-13 22:33 
AnswerRe: WPF.MDI Pin
tram730-Nov-13 5:54
membertram730-Nov-13 5:54 
QuestionSilverlight Dispatcher.BeginInvoke not allow thread to run more then one time Pin
Steve Holdorf24-Jan-13 12:13
memberSteve Holdorf24-Jan-13 12:13 
AnswerRe: Silverlight Dispatcher.BeginInvoke not allow thread to run more then one time Pin
db7uk26-Jan-13 13:11
memberdb7uk26-Jan-13 13:11 
GeneralRe: Silverlight Dispatcher.BeginInvoke not allow thread to run more then one time Pin
Steve Holdorf27-Jan-13 3:19
memberSteve Holdorf27-Jan-13 3:19 
GeneralRe: Silverlight Dispatcher.BeginInvoke not allow thread to run more then one time Pin
db7uk27-Jan-13 12:44
memberdb7uk27-Jan-13 12:44 
GeneralRe: Silverlight Dispatcher.BeginInvoke not allow thread to run more then one time Pin
Steve Holdorf27-Jan-13 13:16
memberSteve Holdorf27-Jan-13 13:16 
QuestionSilverlight OOB access in Online Pin
Sugumaran s23-Jan-13 23:09
memberSugumaran s23-Jan-13 23:09 
AnswerRe: Silverlight OOB access in Online Pin
Richard MacCutchan24-Jan-13 1:50
mvpRichard MacCutchan24-Jan-13 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 27 Aug 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid