Click here to Skip to main content
       

Silverlight / WPF

 
Questionarrange elements inside wpf PinmemberRemix Mixdox1-Feb-13 22:27 
AnswerRe: arrange elements inside wpf PinmvpAbhinav S3-Feb-13 7:02 
QuestionCustom Controls PinmemberSawyer19881-Feb-13 7:05 
QuestionApplication Launcher PinmemberMycroft Holmes31-Jan-13 13:49 
AnswerRe: Application Launcher PinmvpAbhinav S1-Feb-13 8:22 
QuestionWPF controls refresh Pinmembercaradri31-Jan-13 1:50 
AnswerRe: WPF controls refresh PinprotectorPete O'Hanlon31-Jan-13 2:44 
GeneralRe: WPF controls refresh Pinmembercaradri31-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 PinmemberRichard Deeming31-Jan-13 11:25 
GeneralRe: WPF controls refresh [modified] Pinmembercaradri2-Feb-13 17:59 
GeneralRe: WPF controls refresh Pinmembercaradri3-Feb-13 20:16 
QuestionRoutedEvent vs AttachedEvent Pinmemberdevvvy29-Jan-13 22:30 
AnswerRe: RoutedEvent vs AttachedEvent PinprotectorPete O'Hanlon29-Jan-13 22:51 
GeneralRe: RoutedEvent vs AttachedEvent [modified] Pinmemberdevvvy29-Jan-13 23:02 
GeneralRe: RoutedEvent vs AttachedEvent PinprotectorPete O'Hanlon30-Jan-13 0:45 
GeneralRe: RoutedEvent vs AttachedEvent Pinmemberdevvvy30-Jan-13 2:40 
GeneralRe: RoutedEvent vs AttachedEvent PinprotectorPete O'Hanlon30-Jan-13 2:44 
GeneralRe: RoutedEvent vs AttachedEvent Pinmemberdevvvy30-Jan-13 3:08 
QuestionWPF Tab Item Close Button [modified] PinmemberKevin Marois29-Jan-13 18:03 
AnswerRe: WPF Tab Item Close Button PinmemberSledgeHammer0129-Jan-13 19:02 
GeneralRe: WPF Tab Item Close Button PinmemberKevin Marois2-Feb-13 15:33 
GeneralRe: WPF Tab Item Close Button PinmemberSledgeHammer012-Feb-13 18:25 
QuestionCustom Control Template for beginners Pinmemberjeffdavis870329-Jan-13 9:12 
AnswerRe: Custom Control Template for beginners PinmemberSledgeHammer0129-Jan-13 11:32 
GeneralRe: Custom Control Template for beginners Pinmemberjeffdavis870329-Jan-13 12:10 

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
Web04 | 2.8.140905.1 | Last Updated 14 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid