Click here to Skip to main content
15,887,957 members
Home / Discussions / WPF
   

WPF

 
Questionarrange elements inside wpf Pin
Remix Mixdox1-Feb-13 22:27
Remix Mixdox1-Feb-13 22:27 
AnswerRe: arrange elements inside wpf Pin
Abhinav S3-Feb-13 7:02
Abhinav S3-Feb-13 7:02 
QuestionCustom Controls Pin
Sawyer19881-Feb-13 7:05
Sawyer19881-Feb-13 7:05 
QuestionApplication Launcher Pin
Mycroft Holmes31-Jan-13 13:49
professionalMycroft Holmes31-Jan-13 13:49 
AnswerRe: Application Launcher Pin
Abhinav S1-Feb-13 8:22
Abhinav S1-Feb-13 8:22 
QuestionWPF controls refresh Pin
caradri31-Jan-13 1:50
caradri31-Jan-13 1:50 
AnswerRe: WPF controls refresh Pin
Pete O'Hanlon31-Jan-13 2:44
mvePete O'Hanlon31-Jan-13 2:44 
GeneralRe: WPF controls refresh Pin
caradri31-Jan-13 10:20
caradri31-Jan-13 10:20 
Laugh | :laugh:
i really wondered!!!
here is the class that create the files:
C#
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

C#
 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

C#
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
mveRichard Deeming31-Jan-13 11:25 
GeneralRe: WPF controls refresh Pin
caradri2-Feb-13 17:59
caradri2-Feb-13 17:59 
GeneralRe: WPF controls refresh Pin
caradri3-Feb-13 20:16
caradri3-Feb-13 20:16 
QuestionRoutedEvent vs AttachedEvent Pin
devvvy29-Jan-13 22:30
devvvy29-Jan-13 22:30 
AnswerRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon29-Jan-13 22:51
mvePete O'Hanlon29-Jan-13 22:51 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy29-Jan-13 23:02
devvvy29-Jan-13 23:02 
GeneralRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon30-Jan-13 0:45
mvePete O'Hanlon30-Jan-13 0:45 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy30-Jan-13 2:40
devvvy30-Jan-13 2:40 
GeneralRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon30-Jan-13 2:44
mvePete O'Hanlon30-Jan-13 2:44 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy30-Jan-13 3:08
devvvy30-Jan-13 3:08 
QuestionWPF Tab Item Close Button Pin
Kevin Marois29-Jan-13 18:03
professionalKevin Marois29-Jan-13 18:03 
AnswerRe: WPF Tab Item Close Button Pin
SledgeHammer0129-Jan-13 19:02
SledgeHammer0129-Jan-13 19:02 
GeneralRe: WPF Tab Item Close Button Pin
Kevin Marois2-Feb-13 15:33
professionalKevin Marois2-Feb-13 15:33 
GeneralRe: WPF Tab Item Close Button Pin
SledgeHammer012-Feb-13 18:25
SledgeHammer012-Feb-13 18:25 
QuestionCustom Control Template for beginners Pin
jeffdavis870329-Jan-13 9:12
jeffdavis870329-Jan-13 9:12 
AnswerRe: Custom Control Template for beginners Pin
SledgeHammer0129-Jan-13 11:32
SledgeHammer0129-Jan-13 11:32 
GeneralRe: Custom Control Template for beginners Pin
jeffdavis870329-Jan-13 12:10
jeffdavis870329-Jan-13 12:10 

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

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