c# winforms

anoi 21 Reputation points

So for a good 2 weeks I've been trying to make this one function.

It works up to a function that I have to add.

I made a program which takes text from 2 textboxes and a combobox and saves it as a TXT file in the folder that has to be selected when the program starts. It has to work without a database, which is why it involves so many difficulties.

The data is entered by the user in the "Rechnungsssnummertxt.Text". databsankcombobox.Text the selected data is taken. In the case of the trackingcodetxt.Text, a number is randomly generated and the length is taken from NumericUpDown.

Now the program must save all data, both the preselected path and all data created in the program with LOGS.TXT. So not only with the selected path, but also with the LOGS.TXT file.

Before my program saves in the selected path, it has to check whether this data (here either the trackingcodetxt.Text or the invoice number txt.Text) has already been saved, if not the TXT should be saved in the preselected path. If so, the program should open a message box "The data has already been generated".

Here my code:

private void generierenbtn_Click(object sender, EventArgs e)  
//so here check the Logs.txt file before the the step, if also entery has in the Logs.txt file then do nothing give error code, if not make the step under.  
            int stringLength = (int)laengeupdown.Value;  
            trackingcodetxt.Text = "B2B" + GetRandomString(stringLength);  
            string folderPath = Path.Combine(this.pfadtxt.Text, this.trackingcodetxt.Text + ".txt");  
            using (StreamWriter sw = new StreamWriter(folderPath))  
                sw.WriteLine(";" + this.trackingcodetxt.Text + ";;;;;;;;;;;;;;;;;;;;;" + this.rechnungsnummertxt.Text + ";" + this.datenbankcombobox.Text);  
                MessageBox.Show("Erfolgreich", "Auto-Save | V1.0.2", MessageBoxButtons.OK, MessageBoxIcon.Information);  
                clearbtn.Enabled = true;            
                rechnungsnummertxt.Text = "";  
                trackingcodetxt.Text = "";  
                infolabel.Text = "Erfolgreich: " + rechnungsnummertxt.Text;  
                infolabel.ForeColor = Color.DarkGreen;  
        private string GetRandomString(int length)  
            string letters = "qwertzuioplkjhgfdsayxcvbnmQWERTZUIOPLKJHGFDSAYXCVBNBM1234567890";  
            Random random = new Random((int)DateTime.Now.Ticks);  
            string randomString = "";  
            for (int i = 0; i < length; i++)  
                randomString += letters[random.Next(0, letters.Length - 1)];  
            return randomString;  
        private void pfadbtn_Click(object sender, EventArgs e)  
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)  
                pfadtxt.Text = folderBrowserDialog1.SelectedPath;  
                Properties.Settings.Default.datenbanks = datenbankcombobox.Text;  
                Properties.Settings.Default.savefolder = pfadtxt.Text;  
                MessageBox.Show("Pfad automatisch gespeichert zum ändern bitte Programm reseten oder nochmal auswählen!.", "Auto-Save | V1.0.2", MessageBoxButtons.OK, MessageBoxIcon.Information);  
                rechnungsnummertxt.Enabled = true;  
                generierenbtn.Enabled = true;  
                this.Size = new Size(420, 210);  
                MessageBox.Show("Ohne Pfad kann keine Datei erstellt u. gespeichert werden!", "PFAD AUSWÄHLEN!", MessageBoxButtons.OK, MessageBoxIcon.Error);  

Please could someone please help me with this?

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,456 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,400 questions
{count} votes